Skip to main content

DashMapStore

Struct DashMapStore 

Source
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§

Source§

impl<K: Eq + Hash, V> DashMapStore<K, V>

Source

pub fn new() -> Self

Creates an empty store.

discord.js counterpart: new Collection(), which holds discord.js’ caches.

Trait Implementations§

Source§

impl<K: Eq + Hash, V> Debug for DashMapStore<K, V>

Source§

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

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

impl<K: Eq + Hash, V> Default for DashMapStore<K, V>

Source§

fn default() -> Self

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

impl<K, V> Store<K, V> for DashMapStore<K, V>
where K: Eq + Hash + Copy + Send + Sync, V: Send + Sync,

Source§

fn get(&self, key: &K) -> Option<Arc<V>>

Returns the value of key, if any.
Source§

fn insert(&self, key: K, value: Arc<V>) -> Option<Arc<V>>

Inserts or replaces the value of key, returning the previous one.
Source§

fn remove(&self, key: &K) -> Option<Arc<V>>

Removes the value of key, returning it.
Source§

fn len(&self) -> usize

Returns the number of entries.
Source§

fn is_empty(&self) -> bool

Returns whether the store has no entries.
Source§

fn contains_key(&self, key: &K) -> bool

Returns whether key has a value.
Source§

fn retain(&self, keep: &mut dyn FnMut(&K, &V) -> bool)

Removes every entry for which keep returns false. Read more
Source§

fn values(&self) -> Vec<Arc<V>>

Returns a snapshot of every value, in no particular order. Read more
Source§

fn keys(&self) -> Vec<K>

Returns a snapshot of every key, in no particular order, with the same consistency as values.

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>
where K: Send, V: Sync + Send,

§

impl<K, V> Sync for DashMapStore<K, V>
where K: Send + Sync, V: Sync + Send,

§

impl<K, V> Unpin for DashMapStore<K, V>

§

impl<K, V> UnsafeUnpin for DashMapStore<K, V>

§

impl<K, V> UnwindSafe for DashMapStore<K, V>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.