title: Getting "temporary value dropped while borrowed" when trying to update an Option<&str> in a loop
body: <p>I'm trying to implement a commonly used pattern - using the result of a previous loop iteration in the next loop iteration. For example, to implement pagination where you need to give the id of the last value on the previous page.</p>
  
  <pre><code>struct Result {
      str: String,
  }    
  
  fn main() {
      let times = 10;
      let mut last: Option&lt;&amp;str&gt; = None;
  
      for i in 0..times {
          let current = do_something(last);
          last = match current {
              Some(r) =&gt; Some(&amp;r.str.to_owned()),
              None =&gt; None,
          };
      }
  }
  
  fn do_something(o: Option&lt;&amp;str&gt;) -&gt; Option&lt;Result&gt; {
      Some(Result {
          str: "whatever string".to_string(),
      })
  }
  </code></pre>
  
  <p>However, I'm not sure how to actually get the value out of the loop. Currently, the compiler error is <code>temporary value dropped while borrowed</code> (at <code>&amp;r.str.to_owned()</code>), though I made many other attempts, but to no avail.</p>
  
  <p>The only way I found to actually get it working is to create some sort of local <code>tmp_str</code> variable and do a hack like this:</p>
  
  <pre><code>match current {
      Some(r) =&gt; {
          tmp_str.clone_from(&amp;r.str);
          last = Some(&amp;tmp_str);
      }
      None =&gt; {
          last = None;
      }
  }
  </code></pre>
  
  <p>But that doesn't feel like it's the way it's supposed to be done.</p>