Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Remove element from hash

  • remove
  • keys
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"]