Trait MutableKeys

trait MutableKeys: private::Sealed

Opt-in mutable access to IndexMap keys.

These methods expose &mut K, mutable references to the key as it is stored in the map. You are allowed to modify the keys in the map if the modification does not change the key’s hash and equality.

If keys are modified erroneously, you can no longer look them up. This is sound (memory safe) but a logical error hazard (just like implementing PartialEq, Eq, or Hash incorrectly would be).

use this trait to enable its methods for IndexMap.

This trait is sealed and cannot be implemented for types outside this crate.

Associated Types

type Key
type Value

Required Methods

fn get_full_mut2<Q>(self: &mut Self, key: &Q) -> Option<(usize, &mut <Self as >::Key, &mut <Self as >::Value)>
where
    Q: ?Sized + Hash + Equivalent<<Self as >::Key>

Return item index, mutable reference to key and value

Computes in O(1) time (average).

fn get_index_mut2(self: &mut Self, index: usize) -> Option<(&mut <Self as >::Key, &mut <Self as >::Value)>

Return mutable reference to key and value at an index.

Valid indices are 0 <= index < self.len().

Computes in O(1) time.

fn iter_mut2(self: &mut Self) -> IterMut2<'_, <Self as >::Key, <Self as >::Value>

Return an iterator over the key-value pairs of the map, in their order

fn retain2<F>(self: &mut Self, keep: F)
where
    F: FnMut(&mut <Self as >::Key, &mut <Self as >::Value) -> bool

Scan through each key-value pair in the map and keep those where the closure keep returns true.

The elements are visited in order, and remaining elements keep their order.

Computes in O(n) time (average).

Implementors