Enum ordered_multimap::list_ordered_multimap::Entry [−][src]
pub enum Entry<'map, Key, Value, State = RandomState> { Occupied(OccupiedEntry<'map, Key, Value>), Vacant(VacantEntry<'map, Key, Value, State>), }
Expand description
A view into a single entry in the multimap, which may either be vacant or occupied.
Variants
Occupied(OccupiedEntry<'map, Key, Value>)
An occupied entry associated with one or more values.
Vacant(VacantEntry<'map, Key, Value, State>)
A vacant entry with no associated values.
Implementations
impl<'map, Key, Value, State> Entry<'map, Key, Value, State> where
Key: Eq + Hash,
State: BuildHasher,
impl<'map, Key, Value, State> Entry<'map, Key, Value, State> where
Key: Eq + Hash,
State: BuildHasher,
pub fn and_modify<Function>(self, function: Function) -> Self where
Function: FnOnce(&mut Value),
pub fn and_modify<Function>(self, function: Function) -> Self where
Function: FnOnce(&mut Value),
Calls the given function with a mutable reference to the first value of this entry, by insertion order, if it is vacant, otherwise this function is a no-op.
Examples
use ordered_multimap::ListOrderedMultimap; let mut map = ListOrderedMultimap::new(); map.entry("key") .and_modify(|value| *value += 1) .or_insert(42); assert_eq!(map.get(&"key"), Some(&42)); map.entry("key") .and_modify(|value| *value += 1) .or_insert(42); assert_eq!(map.get(&"key"), Some(&43));
If the entry is vacant, the given value will be inserted into it and a mutable reference to that value will be returned. Otherwise, a mutable reference to the first value, by insertion order, will be returned.
Examples
use ordered_multimap::ListOrderedMultimap; let mut map = ListOrderedMultimap::new(); map.insert("key", "value1"); let value = map.entry("key").or_insert("value2"); assert_eq!(value, &"value1"); let value = map.entry("key2").or_insert("value2"); assert_eq!(value, &"value2");
If the entry is vacant, the given value will be inserted into it and the new occupied entry will be returned. Otherwise, the existing occupied entry will be returned.
Examples
use ordered_multimap::ListOrderedMultimap; let mut map = ListOrderedMultimap::new(); map.insert("key", "value1"); let entry = map.entry("key").or_insert_entry("value2"); assert_eq!(entry.into_mut(), &"value1"); let entry = map.entry("key2").or_insert_entry("value2"); assert_eq!(entry.into_mut(), &"value2");
pub fn or_insert_with<Function>(self, function: Function) -> &'map mut Value where
Function: FnOnce() -> Value,
pub fn or_insert_with<Function>(self, function: Function) -> &'map mut Value where
Function: FnOnce() -> Value,
If the entry is vacant, the value returned from the given function will be inserted into it and a mutable reference to that value will be returned. Otherwise, a mutable reference to the first value, by insertion order, will be returned.
Examples
use ordered_multimap::ListOrderedMultimap; let mut map = ListOrderedMultimap::new(); map.insert("key", "value1"); let value = map.entry("key").or_insert_with(|| "value2"); assert_eq!(value, &"value1"); let value = map.entry("key2").or_insert_with(|| "value2"); assert_eq!(value, &"value2");
pub fn or_insert_with_entry<Function>(
self,
function: Function
) -> OccupiedEntry<'map, Key, Value> where
Function: FnOnce() -> Value,
pub fn or_insert_with_entry<Function>(
self,
function: Function
) -> OccupiedEntry<'map, Key, Value> where
Function: FnOnce() -> Value,
If the entry is vacant, the value returned from the given function will be inserted into it and the new occupied entry will be returned. Otherwise, the existing occupied entry will be returned.
Examples
use ordered_multimap::ListOrderedMultimap; let mut map = ListOrderedMultimap::new(); map.insert("key", "value1"); let entry = map.entry("key").or_insert_with_entry(|| "value2"); assert_eq!(entry.into_mut(), &"value1"); let entry = map.entry("key2").or_insert_with_entry(|| "value2"); assert_eq!(entry.into_mut(), &"value2");
Trait Implementations
Auto Trait Implementations
impl<'map, Key, Value, State> RefUnwindSafe for Entry<'map, Key, Value, State> where
Key: RefUnwindSafe,
State: RefUnwindSafe,
Value: RefUnwindSafe,
impl<'map, Key, Value, State> Send for Entry<'map, Key, Value, State> where
Key: Send,
State: Sync,
Value: Send,
impl<'map, Key, Value, State> Sync for Entry<'map, Key, Value, State> where
Key: Sync,
State: Sync,
Value: Sync,
impl<'map, Key, Value, State = RandomState> !UnwindSafe for Entry<'map, Key, Value, State>