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

Check if hash contains key (key exists)

  • from
  • contains_key
  • contains
  • exists
use std::collections::HashMap;

fn main() {
    let counter = HashMap::from([("foo", 1), ("bar", 2)]);
    println!("{:?}", counter.contains_key("zz"));
    println!("{:?}", counter.contains_key("foo"));
}
false
true