| 460 | clippy::integer_division_remainder_used |
| 461 | )] |
| 462 | unsafe fn slice_as_chunks_unchecked<T, const N: usize>(slice: &[T]) -> &[[T; N]] { |
| 463 | // Caller must guarantee that `N` is nonzero and exactly divides the slice length |
| 464 | const { debug_assert!(N != 0) }; |
| 465 | debug_assert_eq!(slice.len() % N, 0); |
| 466 | let new_len = slice.len() / N; |
| 467 | |
| 468 | // SAFETY: We cast a slice of `new_len * N` elements into |
| 469 | // a slice of `new_len` many `N` elements chunks. |
| 470 | unsafe { slice::from_raw_parts(slice.as_ptr().cast(), new_len) } |
| 471 | } |
| 472 | |
| 473 | /// Rust core `[T]::as_chunks_unchecked_mut` vendored because of its 1.88 MSRV. |
| 474 | /// TODO(tarcieri): use upstream function when we bump MSRV |