(slice: &[T])
| 418 | clippy::integer_division_remainder_used |
| 419 | )] |
| 420 | fn 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 |
no test coverage detected