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

Function slice_as_chunks_unchecked

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

Source from the content-addressed store, hash-verified

460 clippy::integer_division_remainder_used
461)]
462unsafe 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

Callers 1

slice_as_chunksFunction · 0.85

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected