Struct elsa::sync::FrozenBTreeMap
source · pub struct FrozenBTreeMap<K, V>(/* private fields */);
Expand description
Append-only threadsafe version of std::collections::BTreeMap
where
insertion does not require mutable access
Implementations§
source§impl<K: Clone + Ord, V: StableDeref> FrozenBTreeMap<K, V>
impl<K: Clone + Ord, V: StableDeref> FrozenBTreeMap<K, V>
pub fn new() -> Self
sourcepub fn get<Q>(&self, k: &Q) -> Option<&V::Target>where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn get<Q>(&self, k: &Q) -> Option<&V::Target>where K: Borrow<Q>, Q: Ord + ?Sized,
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but
Ord
on the borrowed form must match those for
the key type.
Examples
use elsa::sync::FrozenBTreeMap;
let map = FrozenBTreeMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
sourcepub fn insert(&self, k: K, v: V) -> &V::Target
pub fn insert(&self, k: K, v: V) -> &V::Target
Insert a new value into the map. Does nothing if the key is already occupied.
Examples
use elsa::sync::FrozenBTreeMap;
let map = FrozenBTreeMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.get(&1), Some(&"a"));
sourcepub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>where
K: Borrow<Q>,
Q: Ord + ?Sized,
F: FnOnce(&V) -> T,
pub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>where K: Borrow<Q>, Q: Ord + ?Sized, F: FnOnce(&V) -> T,
Applies a function to the owner of the value corresponding to the key (if any).
The key may be any borrowed form of the map’s key type, but
Ord
on the borrowed form must match those for
the key type.
Examples
use elsa::sync::FrozenBTreeMap;
let map = FrozenBTreeMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.map_get(&1, Clone::clone), Some(Box::new("a")));
assert_eq!(map.map_get(&2, Clone::clone), None);
source§impl<K, V> FrozenBTreeMap<K, V>
impl<K, V> FrozenBTreeMap<K, V>
sourcepub fn into_tuple_vec(self) -> Vec<(K, V)>
pub fn into_tuple_vec(self) -> Vec<(K, V)>
Collects the contents of this map into a vector of tuples.
The order of the entries is as if iterating a BTreeMap
(ordered by key).
Examples
use elsa::sync::FrozenBTreeMap;
let map = FrozenBTreeMap::new();
map.insert(1, Box::new("a"));
map.insert(2, Box::new("b"));
let tuple_vec = map.into_tuple_vec();
assert_eq!(tuple_vec, vec![(1, Box::new("a")), (2, Box::new("b"))]);
Trait Implementations§
source§impl<K: Clone + Ord, V: StableDeref> Default for FrozenBTreeMap<K, V>
impl<K: Clone + Ord, V: StableDeref> Default for FrozenBTreeMap<K, V>
source§impl<K: Clone + Ord, V: StableDeref> From<BTreeMap<K, V, Global>> for FrozenBTreeMap<K, V>
impl<K: Clone + Ord, V: StableDeref> From<BTreeMap<K, V, Global>> for FrozenBTreeMap<K, V>
source§impl<K: Clone + Ord, V: StableDeref> FromIterator<(K, V)> for FrozenBTreeMap<K, V>
impl<K: Clone + Ord, V: StableDeref> FromIterator<(K, V)> for FrozenBTreeMap<K, V>
source§impl<Q, K, V> Index<&Q> for FrozenBTreeMap<K, V>where
Q: Ord + ?Sized,
K: Clone + Ord + Borrow<Q>,
V: StableDeref,
impl<Q, K, V> Index<&Q> for FrozenBTreeMap<K, V>where Q: Ord + ?Sized, K: Clone + Ord + Borrow<Q>, V: StableDeref,
Auto Trait Implementations§
impl<K, V> RefUnwindSafe for FrozenBTreeMap<K, V>
impl<K, V> Send for FrozenBTreeMap<K, V>where K: Send, V: Send,
impl<K, V> Sync for FrozenBTreeMap<K, V>where K: Send + Sync, V: Send + Sync,
impl<K, V> Unpin for FrozenBTreeMap<K, V>
impl<K, V> UnwindSafe for FrozenBTreeMap<K, V>
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