title: lifetime with closure captures in rust
body: <p>How can I reduce the lifetime of a closure?</p>
  
  <p>I was trying to make a method, which returns an iterator related to self. I didn't want to make new struct or something, so I just made it return filters and maps, and confronted some borrow checker errors. </p>
  
  <p>The following code was my first try.</p>
  
  <pre><code>fn f&lt;'b&gt;(&amp;'b self) -&gt; impl Iterator&lt;Item = u8&gt; {
      (0..self.some_number())
          .filter(|&amp;i| self.some_bool_function(i))
          .map(|i| i as u8)
  }
  </code></pre>
  
  <p>The following code replicates my question. </p>
  
  <pre class="lang-rust prettyprint-override"><code>struct A(bool);
  
  impl A {
      fn f&lt;'a&gt;(&amp;'a self) -&gt; impl Iterator&lt;Item = u8&gt; + 'a {
          (0..1).filter(|&amp;i| self.0)
      }
  }
  </code></pre>
  
  <p>or even shorter,</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn g&lt;'a&gt;(t:&amp;'a ()) -&gt; impl 'a + FnMut() {
      || *t
  }
  </code></pre>
  
  <p>This would not compile, because the closure may outlive self. I don't know how to make this work, without moving self.</p>