Trait nom::lib::std::ops::IndexMut1.0.0[][src]

pub trait IndexMut<Idx>: Index<Idx> where
    Idx: ?Sized
{ pub fn index_mut(&mut self, index: Idx) -> &mut Self::Output; }
[]

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 std::ops::{Index, IndexMut};

#[derive(Debug)]
enum Side {
    Left,
    Right,
}

#[derive(Debug, PartialEq)]
enum Weight {
    Kilogram(f32),
    Pound(f32),
}

struct Balance {
    pub left: Weight,
    pub right: Weight,
}

impl Index<Side> for Balance {
    type Output = Weight;

    fn index(&self, index: Side) -> &Self::Output {
        println!("Accessing {:?}-side of balance immutably", index);
        match index {
            Side::Left => &self.left,
            Side::Right => &self.right,
        }
    }
}

impl IndexMut<Side> for Balance {
    fn index_mut(&mut self, index: Side) -> &mut Self::Output {
        println!("Accessing {:?}-side of balance mutably", index);
        match index {
            Side::Left => &mut self.left,
            Side::Right => &mut self.right,
        }
    }
}

let mut balance = Balance {
    right: Weight::Kilogram(2.5),
    left: Weight::Pound(1.5),
};

// 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!(balance[Side::Right], Weight::Kilogram(2.5));

// However, in this case `balance[Side::Left]` is sugar for
// `*balance.index_mut(Side::Left)`, since we are writing
// `balance[Side::Left]`.
balance[Side::Left] = Weight::Kilogram(3.0);

Required methods

pub fn index_mut(&mut self, index: Idx) -> &mut Self::Output[src][]

Performs the mutable indexing (container[index]) operation.

Panics

May panic if the index is out of bounds.

Implementations on Foreign Types

impl IndexMut<RangeFull> for OsString[src]

impl<T, I> IndexMut<I> for [T] where
    I: SliceIndex<[T]>, 
[src]

impl<I> IndexMut<I> for str where
    I: SliceIndex<str>, 
[src]

impl<T, I, const N: usize> IndexMut<I> for [T; N] where
    [T]: IndexMut<I>, 
[src]

Implementors

impl IndexMut<Range<usize>> for String1.3.0[src]

impl IndexMut<RangeFrom<usize>> for String1.3.0[src]

impl IndexMut<RangeFull> for String1.3.0[src]

impl IndexMut<RangeInclusive<usize>> for String1.26.0[src]

impl IndexMut<RangeTo<usize>> for String1.3.0[src]

impl IndexMut<RangeToInclusive<usize>> for String1.26.0[src]

impl<A> IndexMut<usize> for VecDeque<A>[src]

impl<T, I, A> IndexMut<I> for Vec<T, A> where
    I: SliceIndex<[T]>,
    A: Allocator
[src]

impl<T, S> IndexMut<usize> for Rgb<T, S>

impl<T, C: AsRef<[T; 3]> + AsMut<[T; 3]>> IndexMut<usize> for AlphaColor<T, C>

impl<K: Key, T> IndexMut<K> for KeyedDenseVec<K, T>

impl<T> IndexMut<Index> for Arena<T>

impl<Buffer> IndexMut<(u8, u32, u32)> for FlatSamples<Buffer> where
    Buffer: IndexMut<usize>, 

impl<P, Container> IndexMut<(u32, u32)> for ImageBuffer<P, Container> where
    P: Pixel + 'static,
    P::Subpixel: 'static,
    Container: Deref<Target = [P::Subpixel]> + DerefMut

impl<T: Primitive> IndexMut<usize> for Rgb<T>

impl<T: Primitive> IndexMut<usize> for Bgr<T>

impl<T: Primitive> IndexMut<usize> for Luma<T>

impl<T: Primitive> IndexMut<usize> for Rgba<T>

impl<T: Primitive> IndexMut<usize> for Bgra<T>

impl<T: Primitive> IndexMut<usize> for LumaA<T>

impl<K, V, Q: ?Sized, S> IndexMut<&'_ Q> for IndexMap<K, V, S> where
    Q: Hash + Equivalent<K>,
    K: Hash + Eq,
    S: BuildHasher

impl<K, V, S> IndexMut<usize> for IndexMap<K, V, S>

impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> IndexMut<usize> for Matrix<N, R, C, S>

impl<N, R: Dim, C: Dim, S> IndexMut<(usize, usize)> for Matrix<N, R, C, S> where
    N: Scalar,
    S: StorageMut<N, R, C>, 

impl<N: Scalar, D: DimName> IndexMut<usize> for Point<N, D> where
    DefaultAllocator: Allocator<N, D>, 

impl<N: Scalar> IndexMut<usize> for Quaternion<N>

impl<N: SimdRealField> IndexMut<usize> for DualQuaternion<N>

impl<N: RealField, D> IndexMut<(usize, usize)> for Transform<N, D, TGeneral> where
    D: DimName + DimNameAdd<U1>,
    DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>, 

impl<N: RealField, T> IndexMut<CollisionObjectSlabHandle> for CollisionObjectSlab<N, T>

impl<'a, C> IndexMut<&'a (usize, usize)> for Matrix<C>

impl<N, E, Ty, Ix> IndexMut<Ix> for Csr<N, E, Ty, Ix> where
    Ty: EdgeType,
    Ix: IndexType

impl<N, E, Ty, Ix> IndexMut<NodeIndex<Ix>> for Graph<N, E, Ty, Ix> where
    Ty: EdgeType,
    Ix: IndexType

impl<N, E, Ty, Ix> IndexMut<EdgeIndex<Ix>> for Graph<N, E, Ty, Ix> where
    Ty: EdgeType,
    Ix: IndexType

impl<'a, G, I> IndexMut<I> for Frozen<'a, G> where
    G: IndexMut<I>, 

impl<N, E, Ty, Ix> IndexMut<NodeIndex<Ix>> for StableGraph<N, E, Ty, Ix> where
    Ty: EdgeType,
    Ix: IndexType

impl<N, E, Ty, Ix> IndexMut<EdgeIndex<Ix>> for StableGraph<N, E, Ty, Ix> where
    Ty: EdgeType,
    Ix: IndexType

impl<N, E, Ty> IndexMut<(N, N)> for GraphMap<N, E, Ty> where
    N: NodeTrait,
    Ty: EdgeType

impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped = E>, Ix: IndexType> IndexMut<NodeIndex<Ix>> for MatrixGraph<N, E, Ty, Null, Ix>

impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped = E>, Ix: IndexType> IndexMut<(NodeIndex<Ix>, NodeIndex<Ix>)> for MatrixGraph<N, E, Ty, Null, Ix>

impl<T> IndexMut<usize> for Mesh<T>

impl<T: RealField> IndexMut<usize> for Polyline<T>

impl IndexMut<TextureRef> for TexturesPool

impl IndexMut<CubemapRef> for TexturesPool

impl IndexMut<SamplerRef> for TexturesPool

impl<M: Key> IndexMut<M> for MaterialPool<M>

impl<M: Key> IndexMut<M> for MaterialCache<M>

impl IndexMut<ProgramRef> for ProgramCache

impl IndexMut<ShadowMapRef> for ShadowMapPool

impl<V: 'static, B: 'static> IndexMut<AllocatorHandle<V, B>> for AllocatorsIndex

impl<T> IndexMut<NodeId> for Arena<T>

impl<'a, Q: ?Sized> IndexMut<&'a Q> for Map<String, Value> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash

impl<I> IndexMut<I> for Value where
    I: Index

impl<T> IndexMut<usize> for Slab<T>

impl<K: Key, V: Slottable> IndexMut<K> for SlotMap<K, V>

impl<K: Key, V> IndexMut<K> for DenseSlotMap<K, V>

impl<K: Key, V: Slottable> IndexMut<K> for HopSlotMap<K, V>

impl<K: Key, V> IndexMut<K> for SecondaryMap<K, V>

impl<K, V, S> IndexMut<K> for SparseSecondaryMap<K, V, S> where
    K: Key,
    S: BuildHasher

impl<A: Array, I: SliceIndex<[A::Item]>> IndexMut<I> for SmallVec<A>

impl<T, P> IndexMut<usize> for Punctuated<T, P>

impl<'a, Q: ?Sized> IndexMut<&'a Q> for Map<String, Value> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash

impl<I> IndexMut<I> for Value where
    I: Index