Skip to main content

MapEntry

Trait MapEntry 

Source
pub trait MapEntry<'a>: Sized {
    type Key;
    type Value: 'a;

    // Required methods
    fn key(&self) -> &Self::Key;
    fn or_insert(self, default: Self::Value) -> &'a mut Self::Value;
    fn or_insert_with<F: FnOnce() -> Self::Value>(
        self,
        default: F,
    ) -> &'a mut Self::Value;
    fn or_default(self) -> &'a mut Self::Value
       where Self::Value: Default;
    fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self;
}
Expand description

Common interface over the native entry types of maps.

Required Associated Types§

Source

type Key

Key type stored in the map.

Source

type Value: 'a

Value type stored in the map.

Required Methods§

Source

fn key(&self) -> &Self::Key

Returns the key associated with this entry.

Source

fn or_insert(self, default: Self::Value) -> &'a mut Self::Value

Inserts the provided value if the entry is vacant, then returns it.

Source

fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value

Inserts a value produced by default if the entry is vacant.

Source

fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default,

Inserts the default value if the entry is vacant.

Source

fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self

Applies f to the value if the entry is occupied.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, K: 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>

Available on crate feature std only.
Source§

type Key = K

Source§

type Value = V

Source§

fn key(&self) -> &Self::Key

Source§

fn or_insert(self, default: Self::Value) -> &'a mut Self::Value

Source§

fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value

Source§

fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default,

Source§

fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self

Source§

impl<'a, K: 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>

Available on crate feature indexmap only.
Source§

type Key = K

Source§

type Value = V

Source§

fn key(&self) -> &Self::Key

Source§

fn or_insert(self, default: Self::Value) -> &'a mut Self::Value

Source§

fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value

Source§

fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default,

Source§

fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self

Source§

impl<'a, K: Eq + Hash + 'a, V: 'a, const N: usize> MapEntry<'a> for Entry<'a, K, V, N>

Available on crate feature heapless only.
Source§

type Key = K

Source§

type Value = V

Source§

fn key(&self) -> &Self::Key

Source§

fn or_insert(self, default: Self::Value) -> &'a mut Self::Value

Source§

fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value

Source§

fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default,

Source§

fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self

Source§

impl<'a, K: Hash + 'a, V: 'a, S: BuildHasher + 'a, A: Allocator + 'a> MapEntry<'a> for Entry<'a, K, V, S, A>

Available on crate feature hashbrown only.
Source§

type Key = K

Source§

type Value = V

Source§

fn key(&self) -> &Self::Key

Source§

fn or_insert(self, default: Self::Value) -> &'a mut Self::Value

Source§

fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value

Source§

fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default,

Source§

fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self

Source§

impl<'a, K: Ord + 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>

Available on crate feature alloc only.
Source§

type Key = K

Source§

type Value = V

Source§

fn key(&self) -> &Self::Key

Source§

fn or_insert(self, default: Self::Value) -> &'a mut Self::Value

Source§

fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value

Source§

fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default,

Source§

fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self

Implementors§