title: Problems with Tuple's lifetime in rust.
body: <p>I'm trying to implement a simple parser for a byte stream.</p>
  
  <p>I'm having troubles when I want to reuse a variable I declared previously,</p>
  
  <pre><code>fn read_data(asn_data: &amp;mut Cursor&lt;&amp;[u8]&gt;) -&gt; Result&lt;(u8, u8, Vec&lt;u8&gt;), Err&gt; {
      let total_len = asn_data.get_ref().len();
  
      if total_len &lt; 2 {
          return Err(1);
      }
      let d_type = asn_data.read_u8().unwrap();
      let d_len = asn_data.read_u8().unwrap();
  
      if (asn_data.position() + d_len as u64) &gt; total_len as u64 {
          return Err(2);
      }
  
      let mut buf = vec![0; d_len as usize];
  
      match asn_data.read_exact(&amp;mut buf) {
          Err(e) =&gt; Err(e),
          Ok(()) =&gt; Ok((d_type, d_len, buf)),
      }
  
  }
  
  fn parse_request(request: &amp;[u8]) -&gt; Option&lt;u8&gt; {
  
      if request.len() == 0 {
          return None;
      }
  
      let mut rdr = Cursor::new(request);
      let data_tuple = read_data(&amp;mut rdr).unwrap();
      println!("{:02?}", data_tuple.2);
  
      rdr = Cursor::new(data_tuple.2.as_slice());
      let data_tuple = read_data(&amp;mut rdr).unwrap();
      println!("{:02x?}", data_tuple.2);
  
      Some(1)
  }
  </code></pre>
  
  <p>In the parse_request function I want to reuse rdr variable, but with the code shown above I get the next error when compiling:</p>
  
  <blockquote>
    <p>error[E0597]: <code>data_tuple.2</code> does not live long enough    -->
    src/main.rs:80:23
        | 80  |     rdr = Cursor::new(data_tuple.2.as_slice());
        |                       ^^^^^^^^^^^^ borrowed value does not live long enough ... 104 | }
        | - <code>data_tuple.2</code> dropped here while still borrowed
        |
        = note: values in a scope are dropped in the opposite order they are created</p>
    
    <p>error: aborting due to previous error</p>
  </blockquote>
  
  <p>However if I write "let mut" when I use the 2nd time rdr variable, the code compiles and works fine... </p>
  
  <pre><code>let mut rdr = Cursor::new(data_tuple.2.as_slice());
  </code></pre>
  
  <p>I don't understand why... what I want is to reuse the variable instead to declare it again...</p>
  
  <p>I tried with some examples/issues related to variable life time but I didn't get the solution for my case... and the solution I found I don't understand fully...</p>