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§
Required Methods§
Sourcefn contains_key(&self, key: &Self::Key) -> bool
fn contains_key(&self, key: &Self::Key) -> bool
Checks whether a given key is contained in the collection.
Sourcefn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>
fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>
Gets a mutable value of the collection.
Sourcefn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)>
fn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)>
Returns iterator over keys and values.
Sourcefn iter_mut(&mut self) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)>
fn iter_mut(&mut self) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)>
Returns iterator over keys and mutable values.
Sourcefn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value>
fn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value>
Constructs iterator over mutable values.
Sourcefn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>
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.
Provided Methods§
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.
impl<K: Eq + Hash, V, S: BuildHasher, A: Allocator> CollectionMap for HashMap<K, V, S, A>
Available on crate feature
hashbrown only.type Key = K
type Value = V
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 keys(&self) -> impl Iterator<Item = &Self::Key>
fn values(&self) -> impl Iterator<Item = &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(&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.
impl<K: Eq + Hash, V, S: BuildHasher, const N: usize> CollectionMap for IndexMap<K, V, S, N>
Available on crate feature
heapless only.type Key = K
type Value = V
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 keys(&self) -> impl Iterator<Item = &Self::Key>
fn values(&self) -> impl Iterator<Item = &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(&K, &mut V) -> bool)
Source§impl<K: Eq + Hash, V, S: BuildHasher> CollectionMap for HashMap<K, V, S>
Available on crate feature std only.
impl<K: Eq + Hash, V, S: BuildHasher> CollectionMap for HashMap<K, V, S>
Available on crate feature
std only.type Key = K
type Value = V
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 keys(&self) -> impl Iterator<Item = &Self::Key>
fn values(&self) -> impl Iterator<Item = &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(&K, &mut V) -> bool)
Source§impl<K: Eq + Hash, V, S: BuildHasher> CollectionMap for IndexMap<K, V, S>
Available on crate feature indexmap only.
impl<K: Eq + Hash, V, S: BuildHasher> CollectionMap for IndexMap<K, V, S>
Available on crate feature
indexmap only.type Key = K
type Value = V
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 keys(&self) -> impl Iterator<Item = &Self::Key>
fn values(&self) -> impl Iterator<Item = &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(&K, &mut V) -> bool)
Source§impl<K: Eq, V, const N: usize> CollectionMap for LinearMap<K, V, N>
Available on crate feature heapless only.
impl<K: Eq, V, const N: usize> CollectionMap for LinearMap<K, V, N>
Available on crate feature
heapless only.type Key = K
type Value = V
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 keys(&self) -> impl Iterator<Item = &Self::Key>
fn values(&self) -> impl Iterator<Item = &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(&K, &mut V) -> bool)
Source§impl<K: Ord, V> CollectionMap for BTreeMap<K, V>
Available on crate feature alloc only.
impl<K: Ord, V> CollectionMap for BTreeMap<K, V>
Available on crate feature
alloc only.