Enum hash_arr_map::map::Entry [−][src]
pub enum Entry<'a, K, V> {
Occupied(OccupiedEntry<'a, K, V>),
Vacant(VacantEntry<'a, K, V>),
}
Expand description
An view into an entry in a Ham
Variants
Occupied(OccupiedEntry<'a, K, V>)
Tuple Fields of Occupied
0: OccupiedEntry<'a, K, V>
Vacant(VacantEntry<'a, K, V>)
Tuple Fields of Vacant
0: VacantEntry<'a, K, V>
Implementations
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value.
Examples
use hash_arr_map::Ham;
let mut map = Ham::new();
map.entry(1).or_insert(5);
assert_eq!(map[&1], 5);
*map.entry(1).or_insert(10) += 1;
assert_eq!(map[&1], 6);
Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value.
Examples
use hash_arr_map::Ham;
let mut map: Ham<u8, String> = Ham::new();
map.entry(6).or_insert_with(|| "pick up sticks".to_string());
assert_eq!(map[&6], "pick up sticks");
Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value. The default function is given a reference to the key, so you can have key-derived values inserted without having to clone the key.
Examples
use hash_arr_map::Ham;
let mut repeats: Ham<usize, String> = Ham::new();
repeats.entry(6).or_insert_with_key(|&n| "x".repeat(n));
assert_eq!(repeats[&6], "xxxxxx");
Returns a reference to this entry’s key.
Examples
use hash_arr_map::Ham;
let mut map: Ham<String, ()> = Ham::new();
assert_eq!(map.entry("rust".into()).key(), "rust");
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
Examples
use hash_arr_map::Ham;
let mut map: Ham<u32, String> = Ham::new();
map.entry(1)
.and_modify(|e| e.push_str(" again"))
.or_insert_with(|| "Hello".to_string());
assert_eq!(map[&1], "Hello");
map.entry(1)
.and_modify(|e| e.push_str(" again"))
.or_insert_with(|| "Hello".to_string());
assert_eq!(map[&1], "Hello again");