(slice: &mut [T])
| 439 | clippy::integer_division_remainder_used |
| 440 | )] |
| 441 | fn 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 |
no test coverage detected