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§
Provided Methods§
Sourcefn split_mut(
&mut self,
at: usize,
) -> Option<(SplitMut<'_, Self>, SplitMut<'_, Self>)>where
Self: Unique,
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]);
Sourcefn copy_from_slice<S>(&mut self, src: &S)
fn copy_from_slice<S>(&mut self, src: &S)
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]);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.