The other answers are outdated. As of Rust 1.27, you can use HashMap::retain
to keep only the elements you are interested in. You specify the elements to keep using a closure.
x.retain(|_, v| *v != 0);
The other answers are outdated. As of Rust 1.27, you can use HashMap::retain
to keep only the elements you are interested in. You specify the elements to keep using a closure.
x.retain(|_, v| *v != 0);