title: How can I iterate over keys of a HashMap and modify the HashMap itself?
body: <p>This is what I'm doing:</p>
  <pre><code>struct Foo {
    m: HashMap&lt;u32, String&gt;
  }
  fn f(foo: &amp;mut Foo) {
    let keys = Vec::new();
    for k in foo.m
      .into_iter()
      .filter(|(k, v)| v &gt; 1)
      .map(|(k, v)| v) { keys.push(k); }
    for k in keys {
      let v = &amp;foo.m.get(k)?;
      // now I do something with v, which in real
      // application is a struct and I will modify it here
    }
  }
  </code></pre>
  <p>However, it says something along these lines:</p>
  <pre><code>error[E0382]: borrow of moved value: `foo.m`
     --&gt; src/foo.rs:56:24
      |
  50  |             .into_iter()
      |              ----------- `foo.m` moved due to this method call
  ...
  56  |             let v = &amp;foo.m.get(k)?;
      |                     ^^^^^^^^^^^^ value borrowed here after move
  
  </code></pre>
  <p>Basically, I'm trying to take the list of necessary keys and copy this list somewhere. Then, iterate over this new already copied list. What am I doing wrong?</p>