Struct elsa::index_map::FrozenIndexMap
source · pub struct FrozenIndexMap<K, V, S = RandomState> { /* private fields */ }
Expand description
Append-only version of indexmap::IndexMap
where
insertion does not require mutable access
Implementations§
source§impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenIndexMap<K, V, S>
impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenIndexMap<K, V, S>
pub fn insert(&self, k: K, v: V) -> &V::Target
pub fn insert_full(&self, k: K, v: V) -> (usize, &V::Target)
sourcepub fn get<Q>(&self, k: &Q) -> Option<&V::Target>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
pub fn get<Q>(&self, k: &Q) -> Option<&V::Target>where K: Borrow<Q>, Q: Hash + Eq + ?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
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use elsa::FrozenIndexMap;
let map = FrozenIndexMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
pub fn get_index(&self, index: usize) -> Option<(&K::Target, &V::Target)>where K: StableDeref,
sourcepub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
F: FnOnce(&V) -> T,
pub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>where K: Borrow<Q>, Q: Hash + Eq + ?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
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use elsa::FrozenIndexMap;
let map = FrozenIndexMap::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);