RefMut

Struct RefMut 

Source
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>
where A: Allocator, V: Value,

Source

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.

Source

pub fn key(&mut self) -> Option<K>
where K: Eq + Hash + Copy, H: BuildHasher + Default,

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

Source

pub fn value(&mut self) -> Option<V>
where K: Eq + Hash + Copy, H: BuildHasher + Default,

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

Source

pub fn key_value(&mut self) -> Option<(K, V)>
where K: Eq + Hash + Copy, H: BuildHasher + Default,

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.

Source

pub fn set_value(&mut self, value: V) -> Option<V>
where K: Eq + Hash + Copy, H: BuildHasher + Default,

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.

Source

pub fn update<F>(&mut self, func: F) -> Option<V>
where K: Eq + Hash + Copy, H: BuildHasher + Default, F: FnMut(&mut 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));

Auto Trait Implementations§

§

impl<'a, K, V, H, A> Freeze for RefMut<'a, K, V, H, A>

§

impl<'a, K, V, H, A> !RefUnwindSafe for RefMut<'a, K, V, H, A>

§

impl<'a, K, V, H, A> Send for RefMut<'a, K, V, H, A>
where H: Sync, A: Sync, K: Copy + Send, V: Copy + Send,

§

impl<'a, K, V, H, A> Sync for RefMut<'a, K, V, H, A>
where H: Sync, A: Sync, K: Copy + Send, V: Copy + Send,

§

impl<'a, K, V, H, A> Unpin for RefMut<'a, K, V, H, A>

§

impl<'a, K, V, H, A> !UnwindSafe for RefMut<'a, K, V, H, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.