pub const fn get_up_to<T>(slice: &[T], len: usize) -> Option<&[T]>
Expand description
A const equivalent of slice.get(..len)
.
§Example
use konst::slice;
const FIBB: &[u16] = &[3, 5, 8, 13, 21, 34, 55, 89];
const TWO: Option<&[u16]> = slice::get_up_to(FIBB, 2);
const FOUR: Option<&[u16]> = slice::get_up_to(FIBB, 4);
const NONE: Option<&[u16]> = slice::get_up_to(FIBB, 0);
const ALL: Option<&[u16]> = slice::get_up_to(FIBB, 1000);
assert_eq!(TWO, Some(&[3, 5][..]));
assert_eq!(FOUR, Some(&[3, 5, 8, 13][..]));
assert_eq!(NONE, Some(&[][..]));
assert_eq!(ALL, None);