Trait IndexMut
pub 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(&mut self, index: Idx) -> &mut Self::OutputPerforms the mutable indexing (
container[index]) operation.Panics
May panic if the index is out of bounds.
Implementors
impl<I> IndexMut<I> for ByteStr where I: SliceIndex<ByteStr>,impl<I> IndexMut<I> for str where I: ~const SliceIndex<str>,impl<I, T, const N: usize> IndexMut<I> for Simd<T, N> where T: SimdElement, I: SliceIndex<[T]>,impl<T, I> IndexMut<I> for [T] where I: ~const SliceIndex<[T]>,impl<T, I, const N: usize> IndexMut<I> for [T; N] where [T]: ~const IndexMut<I>,