HashMap::get_or
pub fn get_or(K k, V fallback) -> V Import
Source: use collections::map::{HashMap}; src/collections/map.hy Returns the value stored under k, or fallback when there is none.
Called on a HashMap value as value.get_or(…).
Parameters#
| Name | Type |
|---|---|
k | K |
fallback | V |
Returns#
V
Examples#
use collections::map::{HashMap};
use tests::assert;
let m: HashMap<string, int> = HashMap::new();
m.insert("a", 1);
assert!(m.get_or("a", 0) == 1);
assert!(m.get_or("b", 0) == 0);
See also#
HashMap: A hash map from keys of typeKto values of typeV.HashMap::with_capacity: Creates an empty map with room for aboutcapbuckets before it grows.HashMap::new: Creates an empty map.HashMap::size: Returns the number of entries.HashMap::is_empty: Returnstruewhen the map has no entries.HashMap::capacity: Returns the number of buckets.HashMap::clear: Removes every entry, keeping the bucket count.HashMap::keys: Returns the keys, in insertion order.