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§
Sourcefn update<Q, F>(&mut self, k: &Q, f: F) -> Option<V>
fn update<Q, F>(&mut self, k: &Q, f: F) -> Option<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.
Sourcefn update_or_insert<F>(&mut self, k: K, f: F, def: V) -> Option<V>
fn update_or_insert<F>(&mut self, k: K, f: F, def: V) -> Option<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.