Struct miri::MonoHashMap
source · pub struct MonoHashMap<K: Hash + Eq, V>(/* private fields */);
Implementations§
source§impl<K: Hash + Eq, V> MonoHashMap<K, V>
impl<K: Hash + Eq, V> MonoHashMap<K, V>
sourcepub fn iter<T>(
&self,
f: impl FnOnce(&mut dyn Iterator<Item = (&K, &V)>) -> T
) -> T
pub fn iter<T>( &self, f: impl FnOnce(&mut dyn Iterator<Item = (&K, &V)>) -> T ) -> T
This function exists for priroda to be able to iterate over all evaluator memory.
The function is somewhat roundabout with the closure argument because internally the
MonoHashMap
uses a RefCell
. When iterating over the FxHashMap
inside the RefCell
,
we need to keep a borrow to the FxHashMap
inside the iterator. The borrow is only alive
as long as the Ref
returned by RefCell::borrow()
is alive. So we can’t return the
iterator, as that would drop the Ref
. We can’t return both, as it’s not possible in Rust
to have a struct/tuple with a field that refers to another field.
Trait Implementations§
source§impl<K: Hash + Eq, V> AllocMap<K, V> for MonoHashMap<K, V>
impl<K: Hash + Eq, V> AllocMap<K, V> for MonoHashMap<K, V>
source§fn get_or<E>(
&self,
k: K,
vacant: impl FnOnce() -> Result<V, E>
) -> Result<&V, E>
fn get_or<E>( &self, k: K, vacant: impl FnOnce() -> Result<V, E> ) -> Result<&V, E>
The most interesting method: Providing a shared reference without
holding the RefCell
open, and inserting new data if the key
is not used yet.
vacant
is called if the key is not found in the map;
if it returns a reference, that is used directly, if it
returns owned data, that is put into the map and returned.
source§fn contains_key<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> boolwhere
K: Borrow<Q>,
fn contains_key<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> boolwhere
K: Borrow<Q>,
&mut
because that is sufficient, and some implementations
can be more efficient then (using RefCell::get_mut
).source§fn contains_key_ref<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> boolwhere
K: Borrow<Q>,
fn contains_key_ref<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> boolwhere
K: Borrow<Q>,
AllocMap::contains_key
] when it is possible to call because it may
be more efficient. This function exists for callers that only have a shared reference
(which might make it slightly less efficient than contains_key
, e.g. if
the data is stored inside a RefCell
).source§fn remove<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> Option<V>where
K: Borrow<Q>,
fn remove<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> Option<V>where
K: Borrow<Q>,
source§fn filter_map_collect<T>(&self, f: impl FnMut(&K, &V) -> Option<T>) -> Vec<T>
fn filter_map_collect<T>(&self, f: impl FnMut(&K, &V) -> Option<T>) -> Vec<T>
source§impl<K: Clone + Hash + Eq, V: Clone> Clone for MonoHashMap<K, V>
impl<K: Clone + Hash + Eq, V: Clone> Clone for MonoHashMap<K, V>
source§fn clone(&self) -> MonoHashMap<K, V>
fn clone(&self) -> MonoHashMap<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more