From 44537142000870549f1f77564952e877d002fd99 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 21 Sep 2025 12:28:35 -0600 Subject: [PATCH] Add `Array::slice_as_flattened(_mut)` As requested in RustCrypto/utils#1221 --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b5288eb..15bab70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -400,6 +400,18 @@ where // SAFETY: `Self` is a `repr(transparent)` newtype for `[T; N]` unsafe { slice::from_raw_parts_mut(slice.as_mut_ptr().cast(), slice.len()) } } + + /// Obtain a flattened slice from a slice of array chunks. + #[inline] + pub fn slice_as_flattened(slice: &[Self]) -> &[T] { + Self::cast_slice_to_core(slice).as_flattened() + } + + /// Obtain a mutable flattened slice from a mutable slice of array chunks. + #[inline] + pub fn slice_as_flattened_mut(slice: &mut [Self]) -> &mut [T] { + Self::cast_slice_to_core_mut(slice).as_flattened_mut() + } } impl Array, U>