Struct miri::mono_hash_map::MonoHashMap
source · pub struct MonoHashMap<K: Hash + Eq, V>(RefCell<FxHashMap<K, Box<V>>>);
Tuple Fields§
§0: RefCell<FxHashMap<K, Box<V>>>
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 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 moreAuto Trait Implementations§
impl<K, V> !RefUnwindSafe for MonoHashMap<K, V>
impl<K, V> Send for MonoHashMap<K, V>where K: Send, V: Send,
impl<K, V> !Sync for MonoHashMap<K, V>
impl<K, V> Unpin for MonoHashMap<K, V>where K: Unpin,
impl<K, V> UnwindSafe for MonoHashMap<K, V>where K: UnwindSafe, V: UnwindSafe,
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
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 40 bytes