title: How to iterate through a Hashmap, print the key/value and remove the value in Rust?
body: <p>This should be a trivial task in any language.   This isn't working in Rust. </p>
  
  <pre><code>use std::collections::HashMap;
  
  fn do_it(map: &amp;mut HashMap&lt;String, String&gt;) {
      for (key, value) in map {
          println!("{} / {}", key, value);
          map.remove(key);
      }
  }
  
  fn main() {}
  </code></pre>
  
  <p>Here's the compiler error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0382]: use of moved value: `*map`
   --&gt; src/main.rs:6:9
    |
  4 |     for (key, value) in map {
    |                         --- value moved here
  5 |         println!("{} / {}", key, value);
  6 |         map.remove(key);
    |         ^^^ value used here after move
    |
    = note: move occurs because `map` has type `&amp;mut std::collections::HashMap&lt;std::string::String, std::string::String&gt;`, which does not implement the `Copy` trait
  </code></pre>
  
  <p>Why it is trying to move a reference?  From the documentation, I didn't think moving/borrowing applied to references.</p>