title: How can I create a struct that takes an iterator?
body: <p>I would like to create a struct that can hold any kind of iterator. A simplified attempt of my actual code is below:</p>
  <pre><code>struct MyStruct&lt;I&gt; {
      my_iter: I,
  }
  
  impl&lt;I&gt; MyStruct&lt;I&gt;
  where 
      I: std::iter::Iterator&lt;Item = usize&gt;,
  {
      fn new(start: usize) -&gt; Self {
          let v: Vec&lt;usize&gt; = vec![start+1, start+2, start+3];
          Self {
              my_iter: v.iter().map(|n| n*2),
          }
      }
  }
  </code></pre>
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=7c7c68dff49b280bb639738233d357fd" rel="nofollow noreferrer">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=7c7c68dff49b280bb639738233d357fd</a></p>
  <p>Unfortunately I get the following error on compilation:</p>
  <pre><code>   Compiling playground v0.0.1 (/playground)
  error[E0308]: mismatched types
    --&gt; src/main.rs:12:22
     |
  5  | impl&lt;I&gt; MyStruct&lt;I&gt;
     |      - this type parameter
  ...
  12 |             my_iter: v.iter().map(|n| n*2),
     |                      ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `I`, found struct `Map`
     |
     = note: expected type parameter `I`
                        found struct `Map&lt;std::slice::Iter&lt;'_, usize&gt;, [closure@src/main.rs:12:35: 12:42]&gt;`
  
  error[E0284]: type annotations needed: cannot satisfy `&lt;_ as Iterator&gt;::Item == usize`
    --&gt; src/main.rs:18:13
     |
  18 |     let _ = MyStruct::new(2);
     |             ^^^^^^^^^^^^^ cannot satisfy `&lt;_ as Iterator&gt;::Item == usize`
     |
  note: required by a bound in `MyStruct::&lt;I&gt;::new`
    --&gt; src/main.rs:7:28
     |
  7  |     I: std::iter::Iterator&lt;Item = usize&gt;,
     |                            ^^^^^^^^^^^^ required by this bound in `MyStruct::&lt;I&gt;::new`
  8  | {
  9  |     fn new(start: usize) -&gt; Self {
     |        --- required by a bound in this
  
  Some errors have detailed explanations: E0284, E0308.
  For more information about an error, try `rustc --explain E0284`.
  error: could not compile `playground` due to 2 previous errors
  </code></pre>
  <p>I can't figure out from the error how to get what I want.</p>