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§
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.
Sourcefn remove(&mut self, key: &Self::Key) -> Option<Self::Value>
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.
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.
impl<K: Eq + Hash, V> KeyedCollection for HashMap<K, V>
Available on crate feature
std only.