pub struct FrozenMap<K, V, S = RandomState> { /* private fields */ }
Expand description
Append-only version of std::collections::HashMap
where
insertion does not require mutable access
Implementations§
source§impl<K: Eq + Hash, V> FrozenMap<K, V>
impl<K: Eq + Hash, V> FrozenMap<K, V>
source§impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenMap<K, V, S>
impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenMap<K, V, S>
sourcepub fn insert(&self, k: K, v: V) -> &V::Target
pub fn insert(&self, k: K, v: V) -> &V::Target
Examples found in repository?
31 32 33 34 35 36 37 38 39 40 41 42 43
pub fn get_resource(&'mgr self, path: &str) -> &'mgr FluentResource<'mgr> {
let strings = &self.strings;
if strings.get(path).is_some() {
return self.resources.get(path).unwrap();
} else {
// pretend to load a file
let string = format!("file for {}", path);
let val = self.strings.insert(path.to_string(), string);
let res = FluentResource::new(val);
self.resources.insert(path.to_string(), Box::new(res))
}
}
sourcepub fn get<Q>(&self, k: &Q) -> Option<&V::Target>
pub fn get<Q>(&self, k: &Q) -> Option<&V::Target>
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 lurk_elsa::FrozenMap;
let map = FrozenMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
Examples found in repository?
31 32 33 34 35 36 37 38 39 40 41 42 43
pub fn get_resource(&'mgr self, path: &str) -> &'mgr FluentResource<'mgr> {
let strings = &self.strings;
if strings.get(path).is_some() {
return self.resources.get(path).unwrap();
} else {
// pretend to load a file
let string = format!("file for {}", path);
let val = self.strings.insert(path.to_string(), string);
let res = FluentResource::new(val);
self.resources.insert(path.to_string(), Box::new(res))
}
}
sourcepub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>
pub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<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 lurk_elsa::FrozenMap;
let map = FrozenMap::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, S> FrozenMap<K, V, S>
impl<K, V, S> FrozenMap<K, V, S>
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 HashMap
(stochastic).
Examples
use lurk_elsa::FrozenMap;
let map = FrozenMap::new();
map.insert(1, Box::new("a"));
map.insert(2, Box::new("b"));
let mut tuple_vec = map.into_tuple_vec();
tuple_vec.sort();
assert_eq!(tuple_vec, vec![(1, Box::new("a")), (2, Box::new("b"))]);
pub fn into_map(self) -> HashMap<K, V, S>
source§impl<K: Eq + Hash + StableDeref, V: StableDeref, S: BuildHasher> FrozenMap<K, V, S>
impl<K: Eq + Hash + StableDeref, V: StableDeref, S: BuildHasher> FrozenMap<K, V, S>
sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K::Target, &V::Target)>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K::Target, &V::Target)>
Returns a reference to the key and value matching a borrowed key.
The key argument 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 lurk_elsa::FrozenMap;
let map = FrozenMap::new();
map.insert(Box::new("1"), Box::new("a"));
assert_eq!(map.get_key_value(&"1"), Some((&"1", &"a")));
assert_eq!(map.get_key_value(&"2"), None);