jam_types

Trait MapLike

Source
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§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn get_mut(&mut self, k: &K) -> Option<&mut V>

Get a mutable reference to the value of the pair with a particular key.

Returns a mutable reference the value of the item in the mapping whose key equals k.

Source

fn keys<'a>(&'a self) -> impl Iterator<Item = &'a K>
where K: 'a,

Get an iterator to all keys in the mapping.

No order is guaranteed.

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 + PartialEq + Ord + PartialOrd, V> MapLike<K, V> for BTreeMap<K, V>

Source§

fn insert(&mut self, k: K, v: V) -> Option<V>

Source§

fn extend(&mut self, iter: impl Iterator<Item = (K, V)>)

Source§

fn contains_key(&self, k: &K) -> bool

Source§

fn remove(&mut self, k: &K) -> Option<V>

Source§

fn get(&self, k: &K) -> Option<&V>

Source§

fn get_mut(&mut self, k: &K) -> Option<&mut V>

Source§

fn keys<'a>(&'a self) -> impl Iterator<Item = &'a K>
where K: 'a,

Source§

impl<K: Eq + Hash, V> MapLike<K, V> for HashMap<K, V>

Source§

fn insert(&mut self, k: K, v: V) -> Option<V>

Source§

fn extend(&mut self, iter: impl Iterator<Item = (K, V)>)

Source§

fn contains_key(&self, k: &K) -> bool

Source§

fn remove(&mut self, k: &K) -> Option<V>

Source§

fn get(&self, k: &K) -> Option<&V>

Source§

fn get_mut(&mut self, k: &K) -> Option<&mut V>

Source§

fn keys<'a>(&'a self) -> impl Iterator<Item = &'a K>
where K: 'a,

Implementors§

Source§

impl<K: Eq + PartialEq + Ord + PartialOrd, V> MapLike<K, V> for VecMap<K, V>