rustc_const_eval::interpret::machine

Trait AllocMap

Source
pub trait AllocMap<K: Hash + Eq, V> {
    // Required methods
    fn contains_key<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> bool
       where K: Borrow<Q>;
    fn contains_key_ref<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> bool
       where K: Borrow<Q>;
    fn insert(&mut self, k: K, v: V) -> Option<V>;
    fn remove<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> Option<V>
       where K: Borrow<Q>;
    fn filter_map_collect<T>(
        &self,
        f: impl FnMut(&K, &V) -> Option<T>,
    ) -> Vec<T>;
    fn get_or<E>(
        &self,
        k: K,
        vacant: impl FnOnce() -> Result<V, E>,
    ) -> Result<&V, E>;
    fn get_mut_or<E>(
        &mut self,
        k: K,
        vacant: impl FnOnce() -> Result<V, E>,
    ) -> Result<&mut V, E>;

    // Provided methods
    fn get(&self, k: K) -> Option<&V> { ... }
    fn get_mut(&mut self, k: K) -> Option<&mut V> { ... }
}
Expand description

The functionality needed by memory to manage its allocations

Required Methods§

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_or<E>( &self, k: K, vacant: impl FnOnce() -> Result<V, E>, ) -> Result<&V, E>

Returns a 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_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.

Provided Methods§

Source

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

Read-only lookup.

Source

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

Mutable lookup.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<K: Hash + Eq, V> AllocMap<K, V> for FxIndexMap<K, V>

Source§

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

Source§

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

Source§

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

Source§

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>

Source§

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

Source§

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

Implementors§