Trait HashmapExt

Source
pub trait HashmapExt<K, V> {
    // Required methods
    fn update<Q, F>(&mut self, k: &Q, f: F) -> Option<V>
       where Q: ?Sized + Hash + Eq,
             K: Borrow<Q> + PartialEq + Eq + Hash,
             V: Clone,
             F: FnMut(&mut V);
    fn update_or_insert<F>(&mut self, k: K, f: F, def: V) -> Option<V>
       where K: PartialEq + Eq + Hash,
             V: Clone,
             F: FnMut(&mut V);
}
Expand description

Extends the HashMap functionality.

Required Methods§

Source

fn update<Q, F>(&mut self, k: &Q, f: F) -> Option<V>
where Q: ?Sized + Hash + Eq, K: Borrow<Q> + PartialEq + Eq + Hash, V: Clone, F: FnMut(&mut V),

Updates the value of a given key in the map.

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

If the map did have this key present, the updated value is returned.

Source

fn update_or_insert<F>(&mut self, k: K, f: F, def: V) -> Option<V>
where K: PartialEq + Eq + Hash, V: Clone, F: FnMut(&mut V),

Updates the value of a given key in the map.

If the map does not have this key present, the provided value is inserted.

If the map did have this key present, the updated value is returned.

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, V> HashmapExt<K, V> for HashMap<K, V>

Source§

fn update<Q, F>(&mut self, k: &Q, f: F) -> Option<V>
where Q: ?Sized + Hash + Eq, K: Borrow<Q> + PartialEq + Eq + Hash, V: Clone, F: FnMut(&mut V),

Source§

fn update_or_insert<F>(&mut self, k: K, f: F, def: V) -> Option<V>
where K: PartialEq + Eq + Hash, V: Clone, F: FnMut(&mut V),

Implementors§