pub const fn bytes_up_to(buffer: &[u8], upto: usize) -> &[u8]
Expand description
Const equivalent of &buffer[..upto]
with saturating indexing.
“saturating indexing” means that if upto > buffer.len()
,
then this returns all of buffer
instead of panicking.
§Example
use const_panic::utils::bytes_up_to;
const BYTES: &[u8] = &[3, 5, 8, 13, 21, 34, 55, 89];
const SLICE: &[u8] = bytes_up_to(BYTES, 4);
assert_eq!(SLICE, &[3, 5, 8, 13][..]);
const WHOLE: &[u8] = bytes_up_to(BYTES, usize::MAX);
assert_eq!(WHOLE, &[3, 5, 8, 13, 21, 34, 55, 89][..]);