pub trait MapLike<K, V> {
// Required methods
fn insert(&mut self, k: K, v: V) -> Option<V>;
fn extend(&mut self, iter: impl Iterator<Item = (K, V)>);
fn contains_key(&self, k: &K) -> bool;
fn remove(&mut self, k: &K) -> Option<V>;
fn get(&self, k: &K) -> Option<&V>;
fn get_mut(&mut self, k: &K) -> Option<&mut V>;
fn keys<'a>(&'a self) -> impl Iterator<Item = &'a K>
where K: 'a;
}Expand description
A data-structure providing the storage and lookup of key/value pairs with exclusive keys.
Required Methods§
Sourcefn insert(&mut self, k: K, v: V) -> Option<V>
fn insert(&mut self, k: K, v: V) -> Option<V>
Insert pair into the mapping.
Inserts some pair (k, v) into the mapping, replacing the existing pair whose key is k,
if any.
Returns Some value which was replaced, if any.
Sourcefn extend(&mut self, iter: impl Iterator<Item = (K, V)>)
fn extend(&mut self, iter: impl Iterator<Item = (K, V)>)
Insert multiple pairs from an iterator.
Replaces any existing pairs which share a key with an element of the iterator.
Sourcefn contains_key(&self, k: &K) -> bool
fn contains_key(&self, k: &K) -> bool
Check if a key is in the mapping.
Returns true iff the mapping contains a pair whose key equals k.
Sourcefn remove(&mut self, k: &K) -> Option<V>
fn remove(&mut self, k: &K) -> Option<V>
Remove an item from the mapping by key.
Removes the item with key equal to k from the mapping.
Returns the value of the item removed, if any.
Sourcefn get(&self, k: &K) -> Option<&V>
fn get(&self, k: &K) -> Option<&V>
Get the value of the pair with a particular key.
Returns a reference the value of the item in the mapping whose key equals k.
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.