pub const fn split_at<T>(slice: &[T], at: usize) -> (&[T], &[T])
Expand description
A const equivalent of
<[T]>::split_at
If at > slice.len()
, this returns a slice
, empty slice pair.
§Const stabilization
The analogous std function was const-stabilized in Rust 1.71.0.
§Example
use konst::slice::split_at;
let arr = [3, 5, 8, 13, 21, 34];
assert_eq!(split_at(&arr, 0), (&[][..], &[3, 5, 8, 13, 21, 34][..]));
assert_eq!(split_at(&arr, 1), (&[3][..], &[5, 8, 13, 21, 34][..]));
assert_eq!(split_at(&arr, 2), (&[3, 5][..], &[8, 13, 21, 34][..]));
assert_eq!(split_at(&arr, 5), (&[3, 5, 8, 13, 21][..], &[34][..]));
assert_eq!(split_at(&arr, 6), (&[3, 5, 8, 13, 21, 34][..], &[][..]));
assert_eq!(split_at(&arr, 7), (&[3, 5, 8, 13, 21, 34][..], &[][..]));