Trait Map

Source
pub trait Map<K, V>: Container
where K: Eq,
{ // Required methods fn get<Q>(&self, key: &Q) -> Option<&V> where K: Borrow<Q>, Q: Eq + ?Sized; fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V> where K: Borrow<Q>, Q: Eq + ?Sized; fn insert(&mut self, k: K, v: V) -> Option<V>; }
Expand description

Trait for a container indexed by a value that implements Eq.

Required Methods§

Source

fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Eq + ?Sized,

Returns a reference to a value from this Map.

Takes a key by reference and returns a reference to the corresponding data, or None if the key doesn’t exist in the map.

Source

fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Eq + ?Sized,

Returns a mutable reference to a value in this map.

Takes a key by reference and returns a mutable reference to the corresponding data, or None if the key doesn’t exist in the map.

Source

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

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned. Note that the key itself isn’t necessarily updated.

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.

Implementors§