pub struct RefMut<'a, K, V, H, A: Allocator> { /* private fields */ }Expand description
A reference type to a cell in a LeapMap which can mutate the referenced
cell value.
Implementations§
Source§impl<'a, K, V, H, A> RefMut<'a, K, V, H, A>
impl<'a, K, V, H, A> RefMut<'a, K, V, H, A>
Sourcepub fn new(
map: &'a LeapMap<K, V, H, A>,
cell: &'a AtomicCell<K, V>,
hash: u64,
) -> RefMut<'a, K, V, H, A>
pub fn new( map: &'a LeapMap<K, V, H, A>, cell: &'a AtomicCell<K, V>, hash: u64, ) -> RefMut<'a, K, V, H, A>
Creates a new mutable reference type referencing the specified cell
and map.
Sourcepub fn key(&mut self) -> Option<K>
pub fn key(&mut self) -> Option<K>
Loads the key for the referenced cell.
This requires &mut self since it’s possible that the underlying data
for the map has been migrated, and that therefore the referenced cell
is out of date, and returning the current value will be incorrect. In
such a case, the cell needs to be updated to reference the correct cell,
hence mut self. This ensures that the returned value is always the
most up to date value.
It is also possible that the cell has been deleted, in which case the
returned value will be None
Sourcepub fn value(&mut self) -> Option<V>
pub fn value(&mut self) -> Option<V>
Loads the value for the referenced cell.
This requires &mut self since it’s possible that the underlying data
for the map has been migrated, and that therefore the referenced cell
is out of date, and returning the current value will be incorrect. In
such a case, the cell needs to be updated to reference the correct cell,
hence mut self. This ensures that the returned value is always the
most up to date value.
It is also possible that the cell has been deleted, in which case the
returned value will be None
Sourcepub fn key_value(&mut self) -> Option<(K, V)>
pub fn key_value(&mut self) -> Option<(K, V)>
Loads the key-value pair for the referenced cell.
This requires &mut self since it’s possible that the underlying data
for the map has been migrated, and that therefore the referenced cell
is out of date, and returning the current value will be incorrect. In
such a case, the cell needs to be updated to reference the correct cell,
hence mut self. This ensures that the returned value is always the
most up to date value.
It is also possible that the cell has been deleted, in which case the
returned value will be None.
Sourcepub fn set_value(&mut self, value: V) -> Option<V>
pub fn set_value(&mut self, value: V) -> Option<V>
Sets the value for the referenced cell, returning the old value if the
cell is still valid, or None if the cell has been deleted.
This requires &mut self since it’s possible that the underlying data
for the map has been migrated, and that therefore the referenced cell
is out of date, and returning the current value will be incorrect. In
such a case, the cell needs to be updated to reference the correct cell,
hence mut self. This ensures that the store is only performed if the
referenced cell is still valid.
Sourcepub fn update<F>(&mut self, func: F) -> Option<V>
pub fn update<F>(&mut self, func: F) -> Option<V>
Updates the value for the referenced cell, using the func to compute
the new value, returning the old value if the cell is still in the map,
and None if the cell has been deleted.
§Examples
let map = leapfrog::LeapMap::new();
map.insert(1, 12);
if let Some(mut kv_ref) = map.get_mut(&1) {
kv_ref.update(|mut v| {
*v += 1;
});
}
assert_eq!(map.get(&1).unwrap().value(), Some(13));