- remove
- keys
Remove element from hash
examples/hashes/remove-from-hash/src/main.rs
use std::collections::HashMap; fn main() { let mut counter = HashMap::from([("foo", 1), ("bar", 2)]); println!("{:?}", counter); println!("{:?}", counter.keys()); let was = counter.remove("foo"); println!("{:?}", was); println!("{:?}", counter); println!("{:?}", counter.keys()); }
{"bar": 2, "foo": 1} ["bar", "foo"] Some(1) {"bar": 2} ["bar"]