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

Function slice_as_chunks_mut

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

Source from the content-addressed store, hash-verified

439 clippy::integer_division_remainder_used
440)]
441fn slice_as_chunks_mut<T, const N: usize>(slice: &mut [T]) -> (&mut [[T; N]], &mut [T]) {
442 assert!(N != 0, "chunk size must be non-zero");
443 let len_rounded_down = slice.len() / N * N;
444 // SAFETY: The rounded-down value is always the same or smaller than the
445 // original length, and thus must be in-bounds of the slice.
446 let (multiple_of_n, remainder) = unsafe { slice.split_at_mut_unchecked(len_rounded_down) };
447 // SAFETY: We already panicked for zero, and ensured by construction
448 // that the length of the subslice is a multiple of N.
449 let array_slice = unsafe { slice_as_chunks_unchecked_mut(multiple_of_n) };
450 (array_slice, remainder)
451}
452
453/// Rust core `[T]::as_chunks_unchecked` vendored because of its 1.88 MSRV.
454/// TODO(tarcieri): use upstream function when we bump MSRV

Callers 1

readMethod · 0.85

Calls 2

lenMethod · 0.80

Tested by

no test coverage detected