Function konst::slice::slice_range_mut

source ·
pub const fn slice_range_mut<T>(
    slice: &mut [T],
    start: usize,
    end: usize
) -> &mut [T]
Available 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.

§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]);