Enum valord_map::Entry
source · pub enum Entry<'v, T, K, V>{
Occupied(RawEntry<'v, T, K, V>),
Vacant(RawEntry<'v, T, K, V>),
}Expand description
Entry for an existing key-value pair in an ValordMap
or a vacant location to insert one.
Variants§
Occupied(RawEntry<'v, T, K, V>)
Existing slot with equivalent key.
Vacant(RawEntry<'v, T, K, V>)
Vacant slot (no equivalent key in the map).
Implementations§
source§impl<'v, T, K, V> Entry<'v, T, K, V>
impl<'v, T, K, V> Entry<'v, T, K, V>
sourcepub fn or_insert_with<F: FnOnce() -> V>(&mut self, default: F) -> &mut V
pub fn or_insert_with<F: FnOnce() -> V>(&mut self, default: F) -> &mut V
sourcepub fn or_insert_with_key<F: FnOnce(&K) -> V>(&mut self, default: F) -> &mut V
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(&mut self, default: F) -> &mut V
Inserts a value produced by the function default with the given key if the entry is vacant,
and returns a mutable reference to the value.
§Examples
use valord_map::ValordMap;
let mut map = ValordMap::new();
map.entry("key").or_insert_with_key(|key| format!("value for {}", key));
assert_eq!(map.get(&"key"), Some(&"value for key".to_string()));Runsourcepub fn and_modify<F>(self, f: F) -> Self
pub fn and_modify<F>(self, f: F) -> Self
Modifies the entry if it is occupied with the function f, and returns the entry.
§Examples
use valord_map::ValordMap;
let mut map = ValordMap::new();
map.entry("key").and_modify(|v| *v = "new value").or_insert("value");
assert_eq!(map.get(&"key"), Some(&"value"));
map.entry("key").and_modify(|v| *v = "new value").or_insert("value");
assert_eq!(map.get(&"key"), Some(&"new value"));RunAuto Trait Implementations§
impl<'v, T, K, V> Freeze for Entry<'v, T, K, V>
impl<'v, T, K, V> RefUnwindSafe for Entry<'v, T, K, V>
impl<'v, T, K, V> Send for Entry<'v, T, K, V>
impl<'v, T, K, V> Sync for Entry<'v, T, K, V>
impl<'v, T, K, V> Unpin for Entry<'v, T, K, V>
impl<'v, T, K, V> !UnwindSafe for Entry<'v, T, K, V>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more