title: Why can't I reuse a &mut reference after passing it to a function that accepts a generic type?
body: <p>Why doesn't this code compile:</p>
  
  <pre><code>fn use_cursor(cursor: &amp;mut io::Cursor&lt;&amp;mut Vec&lt;u8&gt;&gt;) {
      // do some work
  }
  
  fn take_reference(data: &amp;mut Vec&lt;u8&gt;) {
      {
          let mut buf = io::Cursor::new(data);
  
          use_cursor(&amp;mut buf);
      }
  
      data.len();
  }
  
  fn produce_data() {
      let mut data = Vec::new();
      take_reference(&amp;mut data);
      data.len();
  }
  </code></pre>
  
  <p>The error in this case is:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0382]: use of moved value: `*data`
    --&gt; src/main.rs:14:5
     |
  9  |         let mut buf = io::Cursor::new(data);
     |                                       ---- value moved here
  ...
  14 |     data.len();
     |     ^^^^ value used here after move
     |
     = note: move occurs because `data` has type `&amp;mut std::vec::Vec&lt;u8&gt;`, which does not implement the `Copy` trait
  </code></pre>
  
  <p>The signature of <code>io::Cursor::new</code> is such that it takes ownership of its argument. In this case, the argument is a mutable reference to a <code>Vec</code>.</p>
  
  <pre><code>pub fn new(inner: T) -&gt; Cursor&lt;T&gt;
  </code></pre>
  
  <p>It sort of makes sense to me; because <code>Cursor::new</code> takes ownership of its argument (and not a reference) we can't use that value later on. At the same time it doesn't make sense: we essentially only pass a mutable reference and the cursor goes out of scope afterwards anyway.
  In the <code>produce_data</code> function we also pass a mutable reference to <code>take_reference</code>, and it doesn't produce a error when trying to use <code>data</code> again, unlike inside <code>take_reference</code>.</p>
  
  <p>I found it possible to 'reclaim' the reference by using <code>Cursor.into_inner()</code>, but it feels a bit weird to do it manually, since in normal use-cases the borrow-checker is perfectly capable of doing it itself.</p>
  
  <p>Is there a nicer solution to this problem than using <code>.into_inner()</code>? Maybe there's something else I don't understand about the borrow-checker?</p>