Struct StorageMap

Source
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>>
where L: RawRwLock, K: Clone + Eq + Hash, S: BuildHasher,

Source

pub fn with_hasher(hash_builder: S) -> Self

Create a new storage map with the given hasher.

Source

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.

Source

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.

Source

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>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: RawRwLock, M: Default> Default for StorageMap<L, M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<L: Send, M> Send for StorageMap<L, M>

Source§

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>
where L: Unpin, M: Unpin,

§

impl<L, M> UnwindSafe for StorageMap<L, M>
where L: UnwindSafe, M: UnwindSafe,

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.