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§
source§impl<'map, Key, Value, State> Entry<'map, Key, Value, State>
impl<'map, Key, Value, State> Entry<'map, Key, Value, State>
sourcepub fn and_modify<Function>(self, function: Function) -> Selfwhere
Function: FnOnce(&mut Value),
pub fn and_modify<Function>(self, function: Function) -> Selfwhere
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));
sourcepub fn or_insert(self, value: Value) -> &'map mut Value
pub fn or_insert(self, value: Value) -> &'map mut Value
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");
sourcepub fn or_insert_entry(self, value: Value) -> OccupiedEntry<'map, Key, Value>
pub fn or_insert_entry(self, value: Value) -> OccupiedEntry<'map, Key, Value>
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");
sourcepub fn or_insert_with<Function>(self, function: Function) -> &'map mut Valuewhere
Function: FnOnce() -> Value,
pub fn or_insert_with<Function>(self, function: Function) -> &'map mut Valuewhere
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");
sourcepub 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");