Trait IndexMut
trait IndexMut<Idx: ?Sized>: ~const Index<Idx>
Used for indexing operations (container[index]) in mutable contexts.
container[index] is actually syntactic sugar for
*container.index_mut(index), but only when used as a mutable value. If
an immutable value is requested, the Index trait is used instead. This
allows nice things such as v[index] = value.
Examples
A very simple implementation of a Balance struct that has two sides, where
each can be indexed mutably and immutably.
use ;
let mut balance = Balance ;
// In this case, `balance[Side::Right]` is sugar for
// `*balance.index(Side::Right)`, since we are only *reading*
// `balance[Side::Right]`, not writing it.
assert_eq!;
// However, in this case `balance[Side::Left]` is sugar for
// `*balance.index_mut(Side::Left)`, since we are writing
// `balance[Side::Left]`.
balance = Kilogram;
Required Methods
fn index_mut(self: &mut Self, index: Idx) -> &mut <Self as >::OutputPerforms the mutable indexing (
container[index]) operation.Panics
May panic if the index is out of bounds.