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 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 moreAuto Trait Implementations§
impl<K, V> !Freeze for MonoHashMap<K, V>
impl<K, V> !RefUnwindSafe for MonoHashMap<K, V>
impl<K, V> Send for MonoHashMap<K, V>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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