Skip to main content

Map

Trait Map 

Source
pub trait Map<K: Ord + Eq + Hash, V>:
    Default
    + Len
    + Extend<(K, V)>
    + FromIterator<(K, V)>
    + IntoIterator<Item = (K, V)> {
    // Required methods
    fn insert(&mut self, key: K, val: V) -> Result<(), InsertError<V>>;
    fn remove<Q>(&mut self, key: &Q) -> Option<V>
       where K: Borrow<Q>,
             Q: Hash + Eq + Ord;
    fn get<'a, Q: Hash + Eq + Ord>(&'a self, key: &Q) -> Option<&'a V>
       where K: Borrow<Q> + 'a;
    fn get_mut<'a, Q: Hash + Eq + Ord>(
        &'a mut self,
        key: &Q,
    ) -> Option<&'a mut V>
       where K: Borrow<Q> + 'a;
    fn iter(&self) -> Iter<'_, K, V> ;
    fn iter_mut(&mut self) -> IterMut<'_, K, V> ;

    // Provided method
    fn has<Q: Hash + Eq + Ord>(&self, key: &Q) -> bool
       where K: Borrow<Q> { ... }
}
Expand description

An collection of key-value pairs

§Provided implementations

§Requirements

Required Methods§

Source

fn insert(&mut self, key: K, val: V) -> Result<(), InsertError<V>>

See [HashMap.insert]

Source

fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + Ord,

See [HashMap.remove]

Source

fn get<'a, Q: Hash + Eq + Ord>(&'a self, key: &Q) -> Option<&'a V>
where K: Borrow<Q> + 'a,

See [HashMap.get]

Source

fn get_mut<'a, Q: Hash + Eq + Ord>(&'a mut self, key: &Q) -> Option<&'a mut V>
where K: Borrow<Q> + 'a,

See [HashMap.get_mut]

Source

fn iter(&self) -> Iter<'_, K, V>

See [HashMap.iter]

Source

fn iter_mut(&mut self) -> IterMut<'_, K, V>

See [HashMap.iter_mut]

Provided Methods§

Source

fn has<Q: Hash + Eq + Ord>(&self, key: &Q) -> bool
where K: Borrow<Q>,

See [HashMap.contains_key]

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<A: Array<Item = (K, V)>, K: Eq + Hash + Ord, V> Map<K, V> for ArrayVec<A>

Source§

fn insert(&mut self, key: K, val: V) -> Result<(), InsertError<V>>

Source§

fn remove<Q: Hash + Eq + Ord>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>,

Source§

fn get<'a, Q: Hash + Eq + Ord>(&'a self, key: &Q) -> Option<&'a V>
where K: Borrow<Q> + 'a,

Source§

fn get_mut<'a, Q: Hash + Eq + Ord>(&'a mut self, key: &Q) -> Option<&'a mut V>
where K: Borrow<Q> + 'a,

Source§

fn iter(&self) -> Iter<'_, K, V>

Source§

fn iter_mut(&mut self) -> IterMut<'_, K, V>

Source§

impl<K, V> Map<K, V> for Vec<(K, V)>
where K: Ord + Hash,

Available on crate feature alloc only.
Source§

fn insert(&mut self, key: K, val: V) -> Result<(), InsertError<V>>

Source§

fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + Ord,

Source§

fn get<'a, Q: Hash + Eq + Ord>(&'a self, key: &Q) -> Option<&'a V>
where K: Borrow<Q> + 'a,

Source§

fn get_mut<'a, Q: Hash + Eq + Ord>(&'a mut self, key: &Q) -> Option<&'a mut V>
where K: Borrow<Q> + 'a,

Source§

fn iter(&self) -> Iter<'_, K, V>

Source§

fn iter_mut(&mut self) -> IterMut<'_, K, V>

Source§

impl<K: Eq + Hash + Ord, V> Map<K, V> for BTreeMap<K, V>

Available on crate feature alloc only.
Source§

fn insert(&mut self, key: K, val: V) -> Result<(), InsertError<V>>

Source§

fn remove<Q: Ord>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>,

Source§

fn get<'a, Q: Hash + Eq + Ord>(&'a self, key: &Q) -> Option<&'a V>
where K: Borrow<Q> + 'a,

Source§

fn get_mut<'a, Q: Hash + Eq + Ord>(&'a mut self, key: &Q) -> Option<&'a mut V>
where K: Borrow<Q> + 'a,

Source§

fn iter(&self) -> Iter<'_, K, V>

Source§

fn iter_mut(&mut self) -> IterMut<'_, K, V>

Source§

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

Available on crate feature std only.
Source§

fn iter(&self) -> Iter<'_, K, V>

Source§

fn iter_mut(&mut self) -> IterMut<'_, K, V>

Source§

fn get<'a, Q: Hash + Eq + Ord>(&'a self, key: &Q) -> Option<&'a V>
where K: Borrow<Q> + 'a,

Source§

fn get_mut<'a, Q: Hash + Eq + Ord>(&'a mut self, key: &Q) -> Option<&'a mut V>
where K: Borrow<Q> + 'a,

Source§

fn insert(&mut self, key: K, val: V) -> Result<(), InsertError<V>>

Source§

fn remove<Q: Hash + Eq + Ord>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>,

Implementors§