Trait Entry

Source
pub trait Entry<'a> {
    type Key;
    type Value;

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

The Entry trait seeks to establish a common interface for all elements within a so-called keyed container; i.e. on in which elements can be accessed by any type of key.

Required Associated Types§

Required Methods§

Source

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

returns a reference to the key of the entry.

Source

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

if the entry does not exist, insert the provided value and return a mutable reference to it

Source

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

if the entry does not exist, insert the value returned by the provided function and return a mutable reference to it.

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<'a, K, V> Entry<'a> for Entry<'a, K, V>
where K: Ord,

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>(self, f: F) -> &'a mut Self::Value
where F: FnOnce() -> Self::Value,

Source§

impl<'a, K, V> Entry<'a> for Entry<'a, K, V>
where K: Eq + Hash,

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>(self, f: F) -> &'a mut Self::Value
where F: FnOnce() -> Self::Value,

Implementors§