MCPcopy Create free account
hub / github.com/RustCrypto/utils / slice_as_chunks

Function slice_as_chunks

cmov/src/slice.rs:420–430  ·  view source on GitHub ↗
(slice: &[T])

Source from the content-addressed store, hash-verified

418 clippy::integer_division_remainder_used
419)]
420fn slice_as_chunks<T, const N: usize>(slice: &[T]) -> (&[[T; N]], &[T]) {
421 assert!(N != 0, "chunk size must be non-zero");
422 let len_rounded_down = slice.len() / N * N;
423 // SAFETY: The rounded-down value is always the same or smaller than the
424 // original length, and thus must be in-bounds of the slice.
425 let (multiple_of_n, remainder) = unsafe { slice.split_at_unchecked(len_rounded_down) };
426 // SAFETY: We already panicked for zero, and ensured by construction
427 // that the length of the subslice is a multiple of N.
428 let array_slice = unsafe { slice_as_chunks_unchecked(multiple_of_n) };
429 (array_slice, remainder)
430}
431
432/// Rust core `[T]::as_chunks_mut` vendored because of its 1.88 MSRV.
433/// TODO(tarcieri): use upstream function when we bump MSRV

Callers 3

split_blocksMethod · 0.85
pad_detachedMethod · 0.85
pad_detachedMethod · 0.85

Calls 2

lenMethod · 0.80

Tested by

no test coverage detected