Trait slice_utils::SliceMut

source ·
pub trait SliceMut<T>: Slice<T> {
    // Required method
    fn get_mut(&mut self, index: usize) -> Option<&mut T>;

    // Provided methods
    fn slice_mut<R: RangeBounds<usize>>(
        self,
        range: R
    ) -> Option<SliceOfMut<T, Self>> { ... }
    fn map<F>(&mut self, f: F)
       where F: for<'a> FnMut(&mut T) { ... }
}
Expand description

A mutable slice. See Slice for more information.

Required Methods§

source

fn get_mut(&mut self, index: usize) -> Option<&mut T>

Mutably index the slice.

If index < self.len(), this must succeed.

§Examples
let mut slice = [1, 2, 3];
*slice.get_mut(2).unwrap() = 4;
assert_eq!(slice, [1, 2, 4]);

Provided Methods§

source

fn slice_mut<R: RangeBounds<usize>>( self, range: R ) -> Option<SliceOfMut<T, Self>>

Takes a mutable sub-slice, returning None if the range is out-of-bounds.

§Examples
let mut slice = [1, 2, 3, 4, 5];
let mut sliced = (&mut slice).slice_mut(2..).unwrap();
sliced[0] = 0;

assert_eq!(slice, [1, 2, 0, 4, 5]);
source

fn map<F>(&mut self, f: F)
where F: for<'a> FnMut(&mut T),

Calls a closure on each item, mutating it.

§Examples
let mut slice = [1, 2, 3].slice_mut(..).unwrap();
slice.map(|x| *x += 1);
assert_eq!(slice, [2, 3, 4]);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, T> SliceMut<T> for &'a mut [T]

source§

fn get_mut(&mut self, index: usize) -> Option<&mut T>

source§

impl<'a, T, A> SliceMut<T> for &'a mut A
where A: SliceMut<T>,

source§

fn get_mut(&mut self, index: usize) -> Option<&mut T>

source§

impl<T, const N: usize> SliceMut<T> for [T; N]

source§

fn get_mut(&mut self, index: usize) -> Option<&mut T>

Implementors§

source§

impl<T, A> SliceMut<T> for Cycle<T, A>
where A: SliceMut<T>,

source§

impl<T, A> SliceMut<T> for Reverse<T, A>
where A: SliceMut<T>,

source§

impl<T, A> SliceMut<T> for SliceOfMut<T, A>
where A: SliceMut<T>,

source§

impl<T, A, B> SliceMut<T> for Chain<T, A, B>
where A: SliceMut<T>, B: SliceMut<T>,

source§

impl<T, A, B> SliceMut<T> for Interleave<T, A, B>
where A: SliceMut<T>, B: SliceMut<T>,