pub struct Map<K, V, S = RandomState> { /* private fields */ }
Expand description
Sharded, lock-based hash map using the crate default lock
Implementations
sourceimpl<K, V> Map<K, V>
impl<K, V> Map<K, V>
sourcepub fn with_capacity(capacity: usize) -> Self where
K: Debug,
V: Debug,
pub fn with_capacity(capacity: usize) -> Self where
K: Debug,
V: Debug,
Create a new map with the provided capacity. This will distribute the capacity evenly among all the shards (well.. see below)
sourcepub fn with_capacity_and_hasher(
capacity: usize,
hash_builder: RandomState
) -> Self where
K: Debug,
V: Debug,
pub fn with_capacity_and_hasher(
capacity: usize,
hash_builder: RandomState
) -> Self where
K: Debug,
V: Debug,
Create a new map with the provided capacity and hash_builder. This will distribute the capacity evenly among all the shards
sourcepub fn read<'a>(
&'a self,
key: &'a K
) -> (ReadKey<'a, K>, RwLockReadGuard<'a, Shard<K, V>>) where
K: Hash + Eq,
pub fn read<'a>(
&'a self,
key: &'a K
) -> (ReadKey<'a, K>, RwLockReadGuard<'a, Shard<K, V>>) where
K: Hash + Eq,
Get a read guard to the shard corresponding to the provided key
Panics if the shard lock is poisoned
sourcepub fn try_read<'a>(
&'a self,
key: &'a K
) -> Option<(ReadKey<'a, K>, RwLockReadGuard<'a, Shard<K, V>>)> where
K: Hash + Eq,
pub fn try_read<'a>(
&'a self,
key: &'a K
) -> Option<(ReadKey<'a, K>, RwLockReadGuard<'a, Shard<K, V>>)> where
K: Hash + Eq,
Attempt to retrieve a read guard for the shard corresponding to the provided key. If
a writer currently holds the lock, this will return None
Panics if the shard lock is poisoned
sourcepub fn contains<'a>(&'a self, key: &'a K) -> bool where
K: Eq + Hash,
pub fn contains<'a>(&'a self, key: &'a K) -> bool where
K: Eq + Hash,
Does the map contain the provided key
sourcepub fn get_owned<'a>(&'a self, key: &'a K) -> Option<V> where
K: Eq + Hash,
V: Clone,
pub fn get_owned<'a>(&'a self, key: &'a K) -> Option<V> where
K: Eq + Hash,
V: Clone,
Returns a cloned value corresponding to the provided key
sourcepub fn write(&self, key: K) -> (WriteKey<K>, RwLockWriteGuard<'_, Shard<K, V>>) where
K: Hash + Eq,
pub fn write(&self, key: K) -> (WriteKey<K>, RwLockWriteGuard<'_, Shard<K, V>>) where
K: Hash + Eq,
Get a read guard to the shard corresponding to the provided key
Panics if the shard lock is poisoned
sourcepub fn insert(&self, k: K, v: V) -> Option<V> where
K: Hash + Eq,
pub fn insert(&self, k: K, v: V) -> Option<V> where
K: Hash + Eq,
Insert a key value pair into the Map. Returns the existing value at the provided key if there was one.
sourcepub fn remove(&self, k: K) -> Option<V> where
K: Hash + Eq,
pub fn remove(&self, k: K) -> Option<V> where
K: Hash + Eq,
Remove using the provided key. Returns the existing value, if any.
sourcepub fn into_values(self) -> IntoValues<K, V>ⓘNotable traits for IntoValues<K, V>impl<K, V> Iterator for IntoValues<K, V> type Item = V;
pub fn into_values(self) -> IntoValues<K, V>ⓘNotable traits for IntoValues<K, V>impl<K, V> Iterator for IntoValues<K, V> type Item = V;
Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this. Yields the values of the map.
Trait Implementations
sourceimpl<K: 'static, V: 'static> IntoIterator for Map<K, V>
impl<K: 'static, V: 'static> IntoIterator for Map<K, V>
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for Map<K, V, S> where
S: RefUnwindSafe,
impl<K, V, S> Send for Map<K, V, S> where
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for Map<K, V, S> where
K: Send + Sync,
S: Sync,
V: Send + Sync,
impl<K, V, S> Unpin for Map<K, V, S> where
K: Unpin,
S: Unpin,
V: Unpin,
impl<K, V, S> UnwindSafe for Map<K, V, S> where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more