Struct HashMapRef

Source
pub struct HashMapRef<'map, K, V, S, G> { /* private fields */ }
Expand description

A pinned reference to a HashMap.

This type is created with HashMap::pin and can be used to easily access a HashMap without explicitly managing a guard. See the crate-level documentation for details.

Implementations§

Source§

impl<'map, K, V, S, G> HashMapRef<'map, K, V, S, G>
where K: Hash + Eq, S: BuildHasher, G: Guard,

Source

pub fn map(&self) -> &'map HashMap<K, V, S>

Returns a reference to the inner HashMap.

Source

pub fn len(&self) -> usize

Returns the number of entries in the map.

See HashMap::len for details.

Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty. Otherwise returns false.

See HashMap::is_empty for details.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: Equivalent<K> + Hash + ?Sized,

Returns true if the map contains a value for the specified key.

See HashMap::contains_key for details.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where Q: Equivalent<K> + Hash + ?Sized,

Returns a reference to the value corresponding to the key.

See HashMap::get for details.

Source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where Q: Equivalent<K> + Hash + ?Sized,

Returns the key-value pair corresponding to the supplied key.

See HashMap::get_key_value for details.

Source

pub fn insert(&self, key: K, value: V) -> Option<&V>

Inserts a key-value pair into the map.

See HashMap::insert for details.

Source

pub fn try_insert(&self, key: K, value: V) -> Result<&V, OccupiedError<'_, V>>

Tries to insert a key-value pair into the map, and returns a reference to the value that was inserted.

See HashMap::try_insert for details.

Source

pub fn try_insert_with<F>(&self, key: K, f: F) -> Result<&V, &V>
where F: FnOnce() -> V,

Tries to insert a key and value computed from a closure into the map, and returns a reference to the value that was inserted.

See HashMap::try_insert_with for details.

Source

pub fn get_or_insert(&self, key: K, value: V) -> &V

Returns a reference to the value corresponding to the key, or inserts a default value.

See HashMap::get_or_insert for details.

Source

pub fn get_or_insert_with<F>(&self, key: K, f: F) -> &V
where F: FnOnce() -> V,

Returns a reference to the value corresponding to the key, or inserts a default value computed from a closure.

See HashMap::get_or_insert_with for details.

Source

pub fn update<F>(&self, key: K, update: F) -> Option<&V>
where F: Fn(&V) -> V,

Updates an existing entry atomically.

See HashMap::update for details.

Source

pub fn update_or_insert<F>(&self, key: K, update: F, value: V) -> &V
where F: Fn(&V) -> V,

Updates an existing entry or inserts a default value.

See HashMap::update_or_insert for details.

Source

pub fn update_or_insert_with<U, F>(&self, key: K, update: U, f: F) -> &V
where F: FnOnce() -> V, U: Fn(&V) -> V,

Updates an existing entry or inserts a default value computed from a closure.

See HashMap::update_or_insert_with for details.

Source

pub fn compute<'g, F, T>(&'g self, key: K, compute: F) -> Compute<'g, K, V, T>
where F: FnMut(Option<(&'g K, &'g V)>) -> Operation<V, T>,

See HashMap::compute for details.

Source

pub fn remove<Q>(&self, key: &Q) -> Option<&V>
where Q: Equivalent<K> + Hash + ?Sized,

Removes a key from the map, returning the value at the key if the key was previously in the map.

See HashMap::remove for details.

Source

pub fn remove_entry<Q>(&self, key: &Q) -> Option<(&K, &V)>
where Q: Equivalent<K> + Hash + ?Sized,

Removes a key from the map, returning the stored key and value if the key was previously in the map.

See HashMap::remove_entry for details.

Source

pub fn remove_if<Q, F>( &self, key: &Q, should_remove: F, ) -> Result<Option<(&K, &V)>, (&K, &V)>
where Q: Equivalent<K> + Hash + ?Sized, F: FnMut(&K, &V) -> bool,

Conditionally removes a key from the map based on the provided closure.

See HashMap::remove_if for details.

Source

pub fn clear(&self)

Clears the map, removing all key-value pairs.

See HashMap::clear for details.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &V) -> bool,

Retains only the elements specified by the predicate.

See HashMap::retain for details.

Source

pub fn reserve(&self, additional: usize)

Tries to reserve capacity for additional more elements to be inserted in the map.

See HashMap::reserve for details.

Source

pub fn iter(&self) -> Iter<'_, K, V, G>

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&K, &V).

See HashMap::iter for details.

Source

pub fn keys(&self) -> Keys<'_, K, V, G>

An iterator visiting all keys in arbitrary order. The iterator element type is &K.

See HashMap::keys for details.

Source

pub fn values(&self) -> Values<'_, K, V, G>

An iterator visiting all values in arbitrary order. The iterator element type is &V.

See HashMap::values for details.

Trait Implementations§

Source§

impl<K, V, S, G> Debug for HashMapRef<'_, K, V, S, G>
where K: Hash + Eq + Debug, V: Debug, S: BuildHasher, G: Guard,

Source§

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

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

impl<'a, K, V, S, G> IntoIterator for &'a HashMapRef<'_, K, V, S, G>
where K: Hash + Eq, S: BuildHasher, G: Guard,

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V, G>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'map, K, V, S, G> Freeze for HashMapRef<'map, K, V, S, G>
where G: Freeze,

§

impl<'map, K, V, S, G> RefUnwindSafe for HashMapRef<'map, K, V, S, G>

§

impl<'map, K, V, S, G> Send for HashMapRef<'map, K, V, S, G>
where G: Send, K: Send + Sync, V: Send + Sync, S: Sync,

§

impl<'map, K, V, S, G> Sync for HashMapRef<'map, K, V, S, G>
where G: Sync, K: Send + Sync, V: Send + Sync, S: Sync,

§

impl<'map, K, V, S, G> Unpin for HashMapRef<'map, K, V, S, G>
where G: Unpin,

§

impl<'map, K, V, S, G> UnwindSafe for HashMapRef<'map, K, V, S, G>

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> 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, 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.