title: Removing entries from a HashMap based on value
body: <p>I've written the following code (<a href="http://is.gd/weRHua" rel="noreferrer">+ demo</a>) to remove entries from a <code>HashMap</code> based on value. <em>It works, but I feel like I'm struggling against the borrow-checker</em> with the use of:</p>
  
  <ul>
  <li><code>clone()</code> to avoid two references to the same set of keys</li>
  <li>an extra <code>let tmp =</code> binding to increase the lifetime of my temp value</li>
  </ul>
  
  <hr>
  
  <pre><code>use std::collections::HashMap;
  
  fn strip_empties(x: &amp;mut HashMap&lt;String, i8&gt;) {
      let tmp = x.clone();
      let empties = tmp
           .iter()
           .filter(|&amp;(_, &amp;v)| v == 0)
           .map(|(k, _)| k);
  
      for k in empties { x.remove(k); }
  }
  
  fn main() {
      let mut x: HashMap&lt;String, i8&gt; = HashMap::new();
      x.insert("a".to_string(), 1);
      x.insert("b".to_string(), 0);
      strip_empties(&amp;mut x);
  
      println!("Now down to {:?}" , x);
  }
  </code></pre>
  
  <p>Is there a cleaner, more idiomatic way to accomplish this?</p>