title: Confused as to the correct way to create a function that loops through &mut self in rust
body: <p>I am trying to create a function for a struct which loops calling a function on itself, having trouble with lifetimes</p>
  <p>The problem is in this function</p>
  <pre class="lang-rust prettyprint-override"><code>fn next&lt;'b, 'out&gt;(reader_: &amp;mut Reader&lt;B&gt; ) -&gt; Option&lt;(&amp;'out [u8], BytesStart&lt;'out&gt;)&gt; {
      let test = loop {
          let Reader { reader, ns, buf } = reader_;
          let e = reader
              .read_namespaced_event(buf, ns)
              .map(|(ns, e)| (ns.unwrap_or(&amp;[]), e));
          match e {
              Ok((ns, Event::Start(start))) =&gt; {
                  break Some((ns, start));
              }
              _ =&gt; {}
          }
      };
      test
  }
  </code></pre>
  <p>I think the problem comes with the return value but i am not sure how to annotate the lifetimes.</p>
  <p>Full code at: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=381cc6be43934c091b7444c4c8d80dfc" rel="nofollow noreferrer">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=381cc6be43934c091b7444c4c8d80dfc</a></p>
  <p>Using quick-xml.</p>