- get
- from
Get value from hash
- get returns a reference to the value corresponding to the key.
examples/hashes/get-value-from-hash/src/main.rs
use std::collections::HashMap; fn main() { let counter = HashMap::from([ ("foo", 1), ("bar", 2), ]); println!("{}", counter["foo"]); println!("{:?}", counter.get("foo")); // println!("{}", counter["zz"]); // panic println!("{:?}", counter.get("zz")); // None }
1 Some(1) None