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

Function as_chunks_mut

zeroize/src/bulk.rs:102–114  ·  view source on GitHub ↗
(slice: &mut [T])

Source from the content-addressed store, hash-verified

100#[track_caller]
101#[must_use]
102const fn as_chunks_mut<T, const N: usize>(slice: &mut [T]) -> (&mut [[T; N]], &mut [T]) {
103 assert!(N != 0, "chunk size must be non-zero");
104 let len_rounded_down = slice.len() / N * N;
105 // SAFETY: The rounded-down value is always the same or smaller than the
106 // original length, and thus must be in-bounds of the slice.
107 let (multiple_of_n, remainder) = unsafe { slice.split_at_mut_unchecked(len_rounded_down) };
108 // SAFETY: We already panicked for zero, and ensured by construction
109 // that the length of the subslice is a multiple of N. Arrays have the same alignment as T.
110 let array_slice = unsafe {
111 slice::from_raw_parts_mut(multiple_of_n.as_mut_ptr().cast(), multiple_of_n.len() / N)
112 };
113 (array_slice, remainder)
114}

Callers

nothing calls this directly

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected