title: Unable to borrow an iterator as mutable more than once at a time
body: <p>I'm writing a simple tokenizer in Rust but I'm having trouble. I've simplified the code a bit for the sake of this question:</p>
  
  <pre><code>use std::iter::Peekable;
  use std::str::Chars;
  
  struct Example&lt;'a&gt; {
      it: Peekable&lt;Chars&lt;'a&gt;&gt;,
  }
  
  impl&lt;'a&gt; Example&lt;'a&gt; {
      fn tokenize_string(&amp;mut self) {
          loop {
              match self.it.peek() {
                  None =&gt; break,
                  Some(_x) =&gt; self.it.next(),
              };
          }
      }
  }
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0499]: cannot borrow `self.it` as mutable more than once at a time
    --&gt; src/main.rs:13:29
     |
  11 |             match self.it.peek() {
     |                   ------- first mutable borrow occurs here
  12 |                 None =&gt; break,
  13 |                 Some(_x) =&gt; self.it.next(),
     |                             ^^^^^^^ second mutable borrow occurs here
  14 |             };
     |             - first borrow ends here
  </code></pre>
  
  <p>I've been able to work around this by creating a copy of the iterator and calling <code>peek()</code> on that:</p>
  
  <pre><code>fn tokenize_string(&amp;mut self) {
      loop {
          let mut iterator = self.it.clone();
          match iterator.peek() {
              None =&gt; break,
              Some(_x) =&gt; self.it.next(),
          };
      }
  }
  </code></pre>
  
  <p>Is this the best way to do this?  It seems a little hack-ish.</p>