pub struct DashMapStore<K, V> { /* private fields */ }Expand description
A Store backed by a sharded concurrent map ([DashMap]), with keys hashed by
foldhash.
Reads and writes lock one shard of the map for the duration of the call only: values are
handed out as Arc clones, so no lock is held by the caller (D-151).
discord.js counterpart: Collection, which holds discord.js’ caches.
§Examples
use std::sync::Arc;
use djs_cache::{DashMapStore, Store};
let store = DashMapStore::new();
store.insert(1_u64, Arc::new("one"));
assert_eq!(store.get(&1).as_deref(), Some(&"one"));
assert_eq!(store.remove(&1).as_deref(), Some(&"one"));
assert!(store.is_empty());Implementations§
Trait Implementations§
Source§impl<K, V> Store<K, V> for DashMapStore<K, V>
impl<K, V> Store<K, V> for DashMapStore<K, V>
Source§fn insert(&self, key: K, value: Arc<V>) -> Option<Arc<V>>
fn insert(&self, key: K, value: Arc<V>) -> Option<Arc<V>>
Inserts or replaces the value of
key, returning the previous one.Source§fn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
Returns whether
key has a value.Auto Trait Implementations§
impl<K, V> !RefUnwindSafe for DashMapStore<K, V>
impl<K, V> Freeze for DashMapStore<K, V>
impl<K, V> Send for DashMapStore<K, V>
impl<K, V> Sync for DashMapStore<K, V>
impl<K, V> Unpin for DashMapStore<K, V>
impl<K, V> UnsafeUnpin for DashMapStore<K, V>
impl<K, V> UnwindSafe for DashMapStore<K, V>where
K: UnwindSafe,
V: RefUnwindSafe,
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