title: How do I implement an Iterator adapter only for iterators with a specific Item?
body: <p>I'm trying to write a custom adapter for <code>Iterator</code>:</p>
  
  <pre><code>use std::iter::Iterator;
  
  struct LexIter&lt;Iter&gt; {
      last_char: Option&lt;char&gt;,
      iter: Iter,
  }
  
  impl&lt;Iter&gt; LexIter&lt;Iter&gt; {
      fn put_back(&amp;mut self, ch: char) {
          self.last_char = Some(ch);
      }
  }
  
  impl&lt;Iter: Iterator&gt; Iterator for LexIter&lt;Iter&gt; {
      type Item = char;
  
      fn next(&amp;mut self) -&gt; Option&lt;char&gt; {
          match self.last_char {
              Some(ch) =&gt; {
                  let res = ch;
                  self.last_char = None;
                  Some(res)
              }
              None =&gt; self.iter.next(),
          }
      }
  }
  
  impl&lt;Iter: Iterator&gt; std::convert::From&lt;Iter&gt; for LexIter&lt;Iter&gt; {
      fn from(it: Iter) -&gt; Self {
          LexIter {
              last_char: None,
              iter: it,
          }
      }
  }
  </code></pre>
  
  <p>When I compile, I get this error</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: match arms have incompatible types
    --&gt; src/main.rs:18:9
     |
  18 |         match self.last_char {
     |         ^ expected char, found associated type
     |
     = note: expected type `std::option::Option&lt;char&gt;`
     = note:    found type `std::option::Option&lt;&lt;Iter as std::iter::Iterator&gt;::Item&gt;`
  note: match arm with an incompatible type
    --&gt; src/main.rs:24:21
     |
  24 |             None =&gt; self.iter.next(),
     |                     ^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>I understand that <code>self.iter.next()</code> returns <code>Option&lt;Iter::Item&gt;</code>, but I just want to make an adapter for those iterators which has <code>Iterator::Item</code> as <code>char</code>. </p>
  
  <p>Is there way to specify the type explicitly in the function's signature?</p>