Function konst::slice::slice_range_mut [−][src]
pub const fn slice_range_mut<T>(
slice: &mut [T],
start: usize,
end: usize
) -> &mut [T]
This is supported on crate features
mut_refs
or nightly_mut_refs
only.Expand description
A const equivalent of &mut slice[start..end]
.
If start >= end
or slice.len() < start
, this returns an empty slice.
If slice.len() < end
, this returns the slice from start
.
Alternatives
For a const equivalent of &mut slice[start..]
there’s slice_from_mut
.
For a const equivalent of &mut slice[..end]
there’s slice_up_to_mut
.
Performance
If the “constant_time_slice” feature is disabled,
thich takes linear time to remove the leading and trailing elements,
proportional to start + (slice.len() - end)
.
If the “constant_time_slice” feature is enabled, it takes constant time to run, but uses a few nightly features.
Example
use konst::slice::slice_range_mut;
let mut fibb = [3, 5, 8, 13, 21, 34, 55, 89];
assert_eq!(slice_range_mut(&mut fibb, 2, 4), &mut [8, 13]);
assert_eq!(slice_range_mut(&mut fibb, 4, 7), &mut [21, 34, 55]);
assert_eq!(slice_range_mut(&mut fibb, 0, 0), &mut []);
assert_eq!(slice_range_mut(&mut fibb, 0, 1000), &mut [3, 5, 8, 13, 21, 34, 55, 89]);