KeyedCollection

Trait KeyedCollection 

Source
pub trait KeyedCollection: Collection<Item = (Self::Key, Self::Value)> {
    type Key: Eq + Hash;
    type Value;
    type Entry<'a>
       where Self: 'a;

    // Required methods
    fn contains_key(&self, key: &Self::Key) -> bool;
    fn get(&self, key: &Self::Key) -> Option<&Self::Value>;
    fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>;
    fn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)>;
    fn iter_mut(
        &mut self,
    ) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)>;
    fn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value>;
    fn insert(
        &mut self,
        key: Self::Key,
        value: Self::Value,
    ) -> Option<Self::Value>;
    fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>;
    fn entry(&mut self, key: Self::Key) -> Self::Entry<'_>;
    fn retain(&mut self, f: impl FnMut(&Self::Key, &mut Self::Value) -> bool);
}
Expand description

Trait implemented by key-value maps which need to support collection confinement.

Required Associated Types§

Source

type Key: Eq + Hash

Key type for the collection.

Source

type Value

Value type for the collection.

Source

type Entry<'a> where Self: 'a

Required Methods§

Source

fn contains_key(&self, key: &Self::Key) -> bool

Checks whether a given key is contained in the collection.

Source

fn get(&self, key: &Self::Key) -> Option<&Self::Value>

Gets a value of the collection.

Source

fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>

Gets a mutable value of the collection.

Source

fn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)>

Returns iterator over keys and values.

Source

fn iter_mut(&mut self) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)>

Returns iterator over keys and mutable values.

Source

fn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value>

Constructs iterator over mutable values.

Source

fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>

Inserts a new value under a key. Returns previous value if a value under the key was already present in the collection.

Source

fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>

Removes a value stored under a given key, returning an owned value if it was in the collection.

Source

fn entry(&mut self, key: Self::Key) -> Self::Entry<'_>

Gets the given key’s corresponding entry in the map for in-place manipulation.

Source

fn retain(&mut self, f: impl FnMut(&Self::Key, &mut Self::Value) -> bool)

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) for which f(&k, &mut v) returns false. The elements are visited in unsorted (and unspecified) order.

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: Eq + Hash, V> KeyedCollection for HashMap<K, V>

Available on crate feature std only.
Source§

type Key = K

Source§

type Value = V

Source§

type Entry<'a> = Entry<'a, K, V> where K: 'a, V: 'a

Source§

fn contains_key(&self, key: &Self::Key) -> bool

Source§

fn get(&self, key: &Self::Key) -> Option<&Self::Value>

Source§

fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>

Source§

fn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)>

Source§

fn iter_mut(&mut self) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)>

Source§

fn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value>

Source§

fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>

Source§

fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>

Source§

fn entry(&mut self, key: Self::Key) -> Self::Entry<'_>

Source§

fn retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Source§

impl<K: Ord + Hash, V> KeyedCollection for BTreeMap<K, V>

Source§

type Key = K

Source§

type Value = V

Source§

type Entry<'a> = Entry<'a, K, V> where K: 'a, V: 'a

Source§

fn contains_key(&self, key: &Self::Key) -> bool

Source§

fn get(&self, key: &Self::Key) -> Option<&Self::Value>

Source§

fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>

Source§

fn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)>

Source§

fn iter_mut(&mut self) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)>

Source§

fn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value>

Source§

fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>

Source§

fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>

Source§

fn entry(&mut self, key: Self::Key) -> Self::Entry<'_>

Source§

fn retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Implementors§