title: Cannot move out of *** which is behind a mutable reference
body: <p>I have the next code:</p>
  <pre><code>struct Tokenizer {
      reader: BufReader&lt;File&gt;,
      buf: Vec&lt;u8&gt;,
      token: String
  }
  
  impl Tokenizer {
      fn new(path: &amp;PathBuf) -&gt; Tokenizer {
          let file = File::open(path).expect(&quot;Unable to open file!&quot;);
          Tokenizer {
              reader: BufReader::new(file),
              buf: Vec::&lt;u8&gt;::new(),
              token: String::new()
          }
      }
  
      fn next(&amp;mut self) -&gt; bool {
          if self.buf.len() == 0 {
              if self.reader.read_until(b'\n', &amp;mut self.buf)
                  .expect(&quot;Unable to read file&quot;) == 0 {
                  return false;
              }
          }
          let s = String::from_utf8(self.buf).expect(&quot;Unable to read file&quot;);
          let mut start: i8 = -1;
          let mut end: i8 = -1;
          for (i, c) in s.char_indices() {
              if start == -1 {
                  if !c.is_whitespace() {
                      start = i as i8;
                  }
              } else {
                  if c.is_whitespace() {
                      end = i as i8;
                  }
              }
          }
          self.token = s.chars().skip(start as usize).take((end - start) as usize).collect();
          self.buf = s.into_bytes();
          self.buf.clear();
          return true;
      }
  }
  </code></pre>
  <p>But it doesn't work due to error:</p>
  <pre><code>error[E0507]: cannot move out of `self.buf` which is behind a mutable reference
    --&gt; src\parser.rs:28:35
     |
  28 |         let s = String::from_utf8(self.buf).expect(&quot;Unable to read file&quot;);
     |                                   ^^^^^^^^ move occurs because `self.buf` has type `std::vec::Vec&lt;u8&gt;`, which does not implement the `Copy` trait
  </code></pre>
  <p>I've read similar questions that advice to use <code>swap</code> but I didn't get how it will help me. How to fix this error and why does it not compile?</p>