Skip to main content

CollectionMap

Trait CollectionMap 

Source
pub trait CollectionMap: CollectionBase<Item = (Self::Key, Self::Value)> {
    type Key;
    type Value;

    // 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 retain(&mut self, f: impl FnMut(&Self::Key, &mut Self::Value) -> bool);

    // Provided methods
    fn keys(&self) -> impl Iterator<Item = &Self::Key> { ... }
    fn values(&self) -> impl Iterator<Item = &Self::Value> { ... }
}
Expand description

Trait implemented by key-value maps.

Required Associated Types§

Source

type Key

Key type for the collection.

Source

type Value

Value type for the collection.

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

Provided Methods§

Source

fn keys(&self) -> impl Iterator<Item = &Self::Key>

Returns an iterator over the keys.

Source

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

Returns an iterator over the values.

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<K: Eq + Hash, V, S: BuildHasher, A: Allocator> CollectionMap for HashMap<K, V, S, A>

Available on crate feature hashbrown only.
Source§

type Key = K

Source§

type Value = V

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 keys(&self) -> impl Iterator<Item = &Self::Key>

Source§

fn values(&self) -> impl Iterator<Item = &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 retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Source§

impl<K: Eq + Hash, V, S: BuildHasher, const N: usize> CollectionMap for IndexMap<K, V, S, N>

Available on crate feature heapless only.
Source§

type Key = K

Source§

type Value = V

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 keys(&self) -> impl Iterator<Item = &Self::Key>

Source§

fn values(&self) -> impl Iterator<Item = &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 retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Source§

impl<K: Eq + Hash, V, S: BuildHasher> CollectionMap for HashMap<K, V, S>

Available on crate feature std only.
Source§

type Key = K

Source§

type Value = V

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 keys(&self) -> impl Iterator<Item = &Self::Key>

Source§

fn values(&self) -> impl Iterator<Item = &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 retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Source§

impl<K: Eq + Hash, V, S: BuildHasher> CollectionMap for IndexMap<K, V, S>

Available on crate feature indexmap only.
Source§

type Key = K

Source§

type Value = V

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 keys(&self) -> impl Iterator<Item = &Self::Key>

Source§

fn values(&self) -> impl Iterator<Item = &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 retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Source§

impl<K: Eq, V, const N: usize> CollectionMap for LinearMap<K, V, N>

Available on crate feature heapless only.
Source§

type Key = K

Source§

type Value = V

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 keys(&self) -> impl Iterator<Item = &Self::Key>

Source§

fn values(&self) -> impl Iterator<Item = &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 retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Source§

impl<K: Ord, V> CollectionMap for BTreeMap<K, V>

Available on crate feature alloc only.
Source§

type Key = K

Source§

type Value = V

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 keys(&self) -> impl Iterator<Item = &Self::Key>

Source§

fn values(&self) -> impl Iterator<Item = &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 retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Implementors§