pub struct StorageMap<L, M> { /* private fields */ }
Expand description
StorageMap
is a wrapper around HashMap
that allows efficient concurrent
access for the use case when only rarely the missing elements need to be created.
Implementations§
Source§impl<L, K, V, S> StorageMap<L, HashMap<K, V, S>>
impl<L, K, V, S> StorageMap<L, HashMap<K, V, S>>
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Create a new storage map with the given hasher.
Sourcepub fn get_or_create_with<'a, F: FnOnce() -> V>(
&'a self,
key: &K,
create_fn: F,
) -> StorageMapGuard<'a, L, V>
pub fn get_or_create_with<'a, F: FnOnce() -> V>( &'a self, key: &K, create_fn: F, ) -> StorageMapGuard<'a, L, V>
Get a value associated with the key. The method assumes that more often then not the value is already there. If it’s not - the closure will be called to create one. This closure is expected to always produce the same value given the same key.
Sourcepub fn prepare_maybe<F: FnOnce() -> Option<V>>(
&self,
key: &K,
create_fn: F,
) -> PrepareResult
pub fn prepare_maybe<F: FnOnce() -> Option<V>>( &self, key: &K, create_fn: F, ) -> PrepareResult
Make sure the given key is in the map, as a way to warm up future run-time access to the map at the initialization stage.
Sourcepub fn whole_write(&self) -> WholeMapWriteGuard<'_, L, HashMap<K, V, S>>
pub fn whole_write(&self) -> WholeMapWriteGuard<'_, L, HashMap<K, V, S>>
Lock the whole map for writing.
Trait Implementations§
Source§impl<L, M: Debug> Debug for StorageMap<L, M>
impl<L, M: Debug> Debug for StorageMap<L, M>
impl<L: Send, M> Send for StorageMap<L, M>
impl<L: Sync, M> Sync for StorageMap<L, M>
Auto Trait Implementations§
impl<L, M> !Freeze for StorageMap<L, M>
impl<L, M> !RefUnwindSafe for StorageMap<L, M>
impl<L, M> Unpin for StorageMap<L, M>
impl<L, M> UnwindSafe for StorageMap<L, M>where
L: UnwindSafe,
M: UnwindSafe,
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