pub struct Map<K, V> { /* private fields */ }Expand description
A concurrent map, Map is like sync.Map in Golang.
- K must implement
Eq + PartialEq + Hash. - V must implement
Eq + PartialEq + Clone.
Implementations§
Source§impl<K, V> Map<K, V>
impl<K, V> Map<K, V>
Sourcepub fn compare_and_delete(&self, k: K, v: V) -> bool
pub fn compare_and_delete(&self, k: K, v: V) -> bool
compare_and_delete deletes the key-value pair for the given key if the value is equal to the given value. returns true if the kv was already in. returns false if the kv was not in.
Sourcepub fn compare_and_swap(&self, k: K, old_v: V, new_v: V) -> bool
pub fn compare_and_swap(&self, k: K, old_v: V, new_v: V) -> bool
compare_and_swap sets the value for the given key if the value is equal to the given old value. returns true if the kv was already in. returns false if the kv was not in.
Sourcepub fn load(&self, k: K) -> Option<V>
pub fn load(&self, k: K) -> Option<V>
load returns the value stored in the map for a key, or none if no value is present.
Sourcepub fn get<F>(&self, k: K, f: F) -> bool
pub fn get<F>(&self, k: K, f: F) -> bool
without clone: a little faster return true if the key is in the map, false otherwise.
Sourcepub fn load_and_delete(&self, k: K) -> Option<V>
pub fn load_and_delete(&self, k: K) -> Option<V>
load_and_delete deletes the key-value pair for the given key and returns the value
Sourcepub fn load_or_store(&self, k: K, v: V) -> V
pub fn load_or_store(&self, k: K, v: V) -> V
load_or_store returns the existing value for the key if present. otherwise, it stores and returns the given value.