Function konst::slice::slice_from

source ·
pub const fn slice_from<T>(slice: &[T], start: usize) -> &[T]
Expand description

A const equivalent of &slice[start..].

If slice.len() < start, this simply returns an empty slice.

§Example

use konst::slice::slice_from;

const FIBB: &[u16] = &[3, 5, 8, 13, 21, 34, 55, 89];

const TWO: &[u16] = slice_from(FIBB, 2);
const FOUR: &[u16] = slice_from(FIBB, 4);
const ALL: &[u16] = slice_from(FIBB, 0);
const NONE: &[u16] = slice_from(FIBB, 1000);

assert_eq!(TWO, &[8, 13, 21, 34, 55, 89]);
assert_eq!(FOUR, &[21, 34, 55, 89]);
assert_eq!(ALL, FIBB);
assert_eq!(NONE, &[]);