Trait slice_utils::SliceMut

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

    // Provided methods
    fn split_mut(
        &mut self,
        at: usize,
    ) -> Option<(SplitMut<'_, Self>, SplitMut<'_, Self>)>
       where Self: Unique { ... }
    fn copy_from_slice<S>(&mut self, src: &S)
       where S: Slice<Output = Self::Output>,
             S::Output: Clone { ... }
}
Expand description

A Slice that can return mutably borrowed values.

Required Methods§

source

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

Index the slice, returning a mutably borrowed value.

Provided Methods§

source

fn split_mut( &mut self, at: usize, ) -> Option<(SplitMut<'_, Self>, SplitMut<'_, Self>)>
where Self: Unique,

Returns (&mut self[..at], &mut self[at..]). Returns None if at is out-of-bounds.

Analagous to slice::split_mut.

To avoid aliasing, requires Self: Unique.

§Examples
let mut slice = [1, 2, 3, 4, 5];
let (mut left, mut right) = SliceMut::split_mut(&mut slice, 2).unwrap();

assert_eq!(left, [1, 2, 3]);
assert_eq!(right, [4, 5]);

left[0] = 0;
right[0] = 0;
assert_eq!(slice, [0, 2, 3, 0, 5]);
source

fn copy_from_slice<S>(&mut self, src: &S)
where S: Slice<Output = Self::Output>, S::Output: Clone,

Copy all the items from src into self.

Similar to slice::clone_from_slice.

§Panics

The lengths must match. If you only want to copy a sub-slice, you can slice each side down to the desired range.

§Examples
let mut x = [1, 2, 3, 4, 5];
let y = [6, 7];

(&mut x).slice(3..).unwrap().copy_from_slice(&y);
 
assert_eq!(x, [1, 2, 3, 6, 7]);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, S> SliceMut for &'a mut S
where S: SliceMut + ?Sized,

source§

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

source§

impl<T> SliceMut for [T]

source§

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

source§

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

source§

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

Implementors§

source§

impl<A> SliceMut for SliceOf<A>
where A: SliceMut,

source§

impl<A> SliceMut for SplitMut<'_, A>
where A: SliceMut + Unique,

source§

impl<S1, S2> SliceMut for Chain<S1, S2>
where S1: SliceMut, S2: SliceMut<Output = S1::Output>,

source§

impl<S1, S2> SliceMut for Interleave<S1, S2>
where S1: SliceMut, S2: SliceMut<Output = S1::Output>,

source§

impl<S> SliceMut for Cycle<S>
where S: SliceMut,

source§

impl<S> SliceMut for Reverse<S>
where S: SliceMut,