pub enum Entry<'a, K: 'a, V: 'a> {
Occupied(OccupiedEntry<'a, K, V>),
Vacant(VacantEntry<'a, K, V>),
}Expand description
A view into a single entry in a map, which may either be vacant or occupied.
This enum is constructed from the entry method on crate::MuleMap.
Analogous to std::collections::hash_map::Entry
Variants§
Occupied(OccupiedEntry<'a, K, V>)
Vacant(VacantEntry<'a, K, V>)
Implementations§
Source§impl<'a, K, V> Entry<'a, K, V>where
K: PrimInt,
V: PartialEq,
impl<'a, K, V> Entry<'a, K, V>where
K: PrimInt,
V: PartialEq,
Sourcepub fn or_insert(self, default: V) -> &'a mut V
pub fn or_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
§Example
let mut mule_map = mule_map::MuleMap::<u32, usize, fnv_rs::FnvBuildHasher>::new();
mule_map.entry(5).or_insert(3);Analogous to std::collections::hash_map::Entry::or_insert
Sourcepub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
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 in the entry.
§Example
let mut mule_map = mule_map::MuleMap::<u32, usize, fnv_rs::FnvBuildHasher>::new();
mule_map.entry(5).or_insert_with(|| 1 + 1);Analogous to std::collections::hash_map::Entry::or_insert_with
Sourcepub fn or_insert_with_key<F: FnOnce(K) -> V>(self, default: F) -> &'a mut V
pub fn or_insert_with_key<F: FnOnce(K) -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting, if empty, the result of the default function.
§Example
let mut mule_map = mule_map::MuleMap::<u32, usize, fnv_rs::FnvBuildHasher>::new();
mule_map.entry(5).or_insert_with_key(|key| key as usize + 1);Analogous to std::collections::hash_map::Entry::or_insert_with_key
Sourcepub fn key(&self) -> K
pub fn key(&self) -> K
Returns this entry’s key.
§Example
let mut mule_map = mule_map::MuleMap::<u32, usize, fnv_rs::FnvBuildHasher>::new();
assert_eq!(mule_map.entry(5).key(), 5);Analogous to std::collections::hash_map::Entry::key
Sourcepub fn and_modify<F>(self, f: F) -> Self
pub fn and_modify<F>(self, f: F) -> Self
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
§Example
let mut mule_map = mule_map::MuleMap::<u32, usize, fnv_rs::FnvBuildHasher>::new();
mule_map.entry(5).and_modify(|e| *e += 1).or_insert(1);Analogous to std::collections::hash_map::Entry::and_modify
Sourcepub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V>
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V>
Sets the value of the entry, and returns an OccupiedEntry.
§Example
let mut mule_map = mule_map::MuleMap::<u32, usize, fnv_rs::FnvBuildHasher>::new();
let entry = mule_map.entry(5).insert_entry(10);Analogous to std::collections::hash_map::Entry::insert_entry