miri::mono_hash_map

Struct 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>

Source

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>

Source§

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 get(&self, k: K) -> Option<&V>

Read-only lookup (avoid read-acquiring the RefCell).

Source§

fn contains_key<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> bool
where K: Borrow<Q>,

Tests if the map contains the given key. Deliberately takes &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) -> bool
where K: Borrow<Q>,

Callers should prefer 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 insert(&mut self, k: K, v: V) -> Option<V>

Inserts a new entry into the map.
Source§

fn remove<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>,

Removes an entry from the map.
Source§

fn filter_map_collect<T>(&self, f: impl FnMut(&K, &V) -> Option<T>) -> Vec<T>

Returns data based on the keys and values in the map.
Source§

fn get_mut_or<E>( &mut self, k: K, vacant: impl FnOnce() -> Result<V, E>, ) -> Result<&mut V, E>

Returns a mutable reference to entry k. If no such entry exists, call vacant and either forward its error, or add its result to the map and return a reference to that.
Source§

fn get_mut(&mut self, k: K) -> Option<&mut V>

Mutable lookup.
Source§

impl<K: Clone + Hash + Eq, V: Clone> Clone for MonoHashMap<K, V>

Source§

fn clone(&self) -> MonoHashMap<K, V>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug + Hash + Eq, V: Debug> Debug for MonoHashMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Hash + Eq, V> Default for MonoHashMap<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto 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>
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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

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