indexmap::set

Trait MutableValues

source
pub trait MutableValues: Sealed {
    type Value;

    // Required methods
    fn get_full_mut2<Q>(
        &mut self,
        value: &Q,
    ) -> Option<(usize, &mut Self::Value)>
       where Q: ?Sized + Hash + Equivalent<Self::Value>;
    fn get_index_mut2(&mut self, index: usize) -> Option<&mut Self::Value>;
    fn retain2<F>(&mut self, keep: F)
       where F: FnMut(&mut Self::Value) -> bool;
}
Expand description

Opt-in mutable access to IndexSet values.

These methods expose &mut T, mutable references to the value as it is stored in the set. You are allowed to modify the values in the set if the modification does not change the value’s hash and equality.

If values 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 IndexSet.

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

Required Associated Types§

Required Methods§

source

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

Return item index and mutable reference to the value

Computes in O(1) time (average).

source

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

Return mutable reference to the value at an index.

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

Computes in O(1) time.

source

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

Scan through each value in the set and keep those where the closure keep returns true.

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

Computes in O(n) time (average).

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, S> MutableValues for IndexSet<T, S>
where S: BuildHasher,

Opt-in mutable access to IndexSet values.

See MutableValues for more information.

source§

type Value = T