[−][src]Function const_format::utils::slice_up_to_len_alt
pub const fn slice_up_to_len_alt<T>(slice: &[T], len: usize) -> &[T]
A const equivalent of &slice[..len]
.
If slice.len() < len
, this simply returns slice
back.
Runtime
If the "constant_time_as_str" feature is disabled,
thich takes linear time to remove the trailing elements,
proportional to slice.len() - len
.
If the "constant_time_as_str" feature is enabled, it takes constant time to run, but uses a few additional nightly features.
Example
use const_format::utils::slice_up_to_len_alt; const FIBB: &[u16] = &[3, 5, 8, 13, 21, 34, 55, 89]; const TWO: &[u16] = slice_up_to_len_alt(FIBB, 2); const FOUR: &[u16] = slice_up_to_len_alt(FIBB, 4); const ALL: &[u16] = slice_up_to_len_alt(FIBB, usize::MAX); assert_eq!(TWO, &[3, 5]); assert_eq!(FOUR, &[3, 5, 8, 13]); assert_eq!(FIBB, ALL);