title: Rust: return reference to member variable in a function in an `impl`
body: <p>How do I scope the lifetime for a function that returns a reference to a member variable? The reference will be valid as long as the struct is alive.</p>
  
  <p>Here is an example where one might want this:</p>
  
  <pre><code>struct CountUpIter&lt;'a, T&gt; {
      output: &amp;'a mut T,
  }
  
  fn next&lt;'a, T&gt;(selff: &amp;'a mut CountUpIter&lt;'a, T&gt;) -&gt; Option&lt;&amp;'a T&gt; {
      Some(&amp;selff.output)
  }
  
  // This does not work
  // first, the lifetime cannot outlive the lifetime '_ as defined on the impl so that reference does not outlive borrowed content
  // but, the lifetime must be valid for the lifetime 'a as defined on the impl
  impl&lt;'a, T&gt; Iterator for CountUpIter&lt;'a, T&gt; {
      type Item = &amp;'a T;
      fn next(&amp;mut self) -&gt; Option&lt;Self::Item&gt; {
          Some(&amp;self.output)
      }
  }
  
  // Neither does this. It fails with the same error
  impl&lt;'a, T&gt; Iterator for &amp;mut CountUpIter&lt;'a, T&gt; {
      type Item = &amp;'a T;
      fn next(&amp;mut self) -&gt; Option&lt;Self::Item&gt; {
          Some(&amp;self.output)
      }
  }
  </code></pre>
  
  <p>I have matched as much as possible the solution to <a href="https://stackoverflow.com/a/30422716/1078199">this question</a>, but I want to iterate over <code>&amp;T</code> not <code>Vec&lt;&amp;T&gt;</code>.</p>