Struct lib_wc::sync::ds::BasicSharedMap
source · pub struct BasicSharedMap<K, V> { /* private fields */ }
Expand description
A shared map that can be cloned and used in multiple threads
Implementations§
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new shared map
Examples
use lib_wc::sync::ds::BasicSharedMap;
let m: BasicSharedMap<u32, String> = BasicSharedMap::new();
sourcepub fn insert(&self, key: K, value: V)
pub fn insert(&self, key: K, value: V)
Insert a key-value pair into the map
Examples
use lib_wc::sync::ds::BasicSharedMap;
let m: BasicSharedMap<u32, String> = BasicSharedMap::new();
m.insert(1, "foo".to_string());
sourcepub fn get(&self, key: &K) -> Option<V>where
V: Clone,
pub fn get(&self, key: &K) -> Option<V>where V: Clone,
Get a value from the map
Examples
use lib_wc::sync::ds::BasicSharedMap;
let m: BasicSharedMap<u32, String> = BasicSharedMap::new();
m.insert(1, "foo".to_string());
assert_eq!(m.get(&1), Some("foo".to_string()));
sourcepub fn with_map<F, R>(&self, func: F) -> Result<R>where
F: FnOnce(&mut HashMap<K, V>) -> R,
pub fn with_map<F, R>(&self, func: F) -> Result<R>where F: FnOnce(&mut HashMap<K, V>) -> R,
Atomically execute a function with a locked, mutable reference to the map
Examples
use lib_wc::sync::ds::BasicSharedMap;
let m: BasicSharedMap<u32, String> = BasicSharedMap::new();
m.with_map(|map| {
map.insert(1, "foo".to_string());
map.insert(2, "bar".to_string());
});
assert_eq!(m.get(&1), Some("foo".to_string()));
assert_eq!(m.get(&2), Some("bar".to_string()));
Trait Implementations§
source§fn clone(&self) -> BasicSharedMap<K, V>
fn clone(&self) -> BasicSharedMap<K, V>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more