Trait map_ext::UpdateOr [] [src]

pub trait UpdateOr<K, V> {
    fn update_or<F>(&mut self, key: &K, f: F, default: V)
    where
        F: FnOnce(&mut V)
; }

Trait adding an update_or method to maps, allowing their entries to be updated with a default value.

Required Methods

Update the entry for given key, or insert a default.

If there is an entry in the map corresponding to key, updates the value by applying the function f to it. Otherwise, if there is no entry, inserts the default value into the map for that key.

Arguments

  • key: the key to the entry to update
  • f: a function taking &mut V to update the entry's value
  • default: a default value to insert if there is no existing value

Implementors