diff --git a/hybrid-array/src/impls.rs b/hybrid-array/src/impls.rs index 55542ffc..f578b1d8 100644 --- a/hybrid-array/src/impls.rs +++ b/hybrid-array/src/impls.rs @@ -1,26 +1,6 @@ -use super::{Array, ArrayOps, ArraySize, AssociatedArraySize}; - -#[cfg(feature = "zeroize")] -use zeroize::{Zeroize, ZeroizeOnDrop}; - -#[cfg(feature = "zeroize")] -impl Zeroize for Array -where - T: Zeroize, - U: ArraySize, -{ - fn zeroize(&mut self) { - self.0.as_mut().iter_mut().zeroize() - } -} +//! Macros for defining various array sizes, and their associated invocations. -#[cfg(feature = "zeroize")] -impl ZeroizeOnDrop for Array -where - T: ZeroizeOnDrop, - U: ArraySize, -{ -} +use super::{Array, ArrayOps, ArraySize, AssociatedArraySize}; macro_rules! impl_array_size { ($($len:expr => $ty:ident),+) => { @@ -159,43 +139,3 @@ impl_array_size! { 4096 => U4096, 8192 => U8192 } - -impl ArrayOps for [T; N] -where - Self: AssociatedArraySize, -{ - const SIZE: usize = N; - - #[inline] - fn as_core_array(&self) -> &[T; N] { - self - } - - #[inline] - fn as_mut_core_array(&mut self) -> &mut [T; N] { - self - } - - #[inline] - fn from_core_array(arr: [T; N]) -> Self { - arr - } - - #[inline] - fn ref_from_core_array(array_ref: &[T; N]) -> &Self { - array_ref - } - - #[inline] - fn ref_from_mut_core_array(array_ref: &mut [T; N]) -> &mut Self { - array_ref - } - - #[inline] - fn map_to_core_array(self, f: F) -> [U; N] - where - F: FnMut(T) -> U, - { - self.map(f) - } -} diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index 706ae47b..2df096c2 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -23,6 +23,8 @@ unused_qualifications )] +mod impls; + pub use typenum; pub use typenum::consts; @@ -39,7 +41,8 @@ use core::{ }; use typenum::{Diff, Sum, Unsigned}; -mod impls; +#[cfg(feature = "zeroize")] +use zeroize::{Zeroize, ZeroizeOnDrop}; /// Hybrid typenum-based and const generic array type. /// @@ -532,6 +535,25 @@ where } } +#[cfg(feature = "zeroize")] +impl Zeroize for Array +where + T: Zeroize, + U: ArraySize, +{ + fn zeroize(&mut self) { + self.0.as_mut().iter_mut().zeroize() + } +} + +#[cfg(feature = "zeroize")] +impl ZeroizeOnDrop for Array +where + T: ZeroizeOnDrop, + U: ArraySize, +{ +} + /// Generate a [`TryFromSliceError`] if the slice doesn't match the given length. #[cfg_attr(debug_assertions, allow(clippy::panic_in_result_fn))] fn check_slice_length(slice: &[T]) -> Result<(), TryFromSliceError> { @@ -587,6 +609,46 @@ pub trait ArrayOps: F: FnMut(T) -> U; } +impl ArrayOps for [T; N] +where + Self: AssociatedArraySize, +{ + const SIZE: usize = N; + + #[inline] + fn as_core_array(&self) -> &[T; N] { + self + } + + #[inline] + fn as_mut_core_array(&mut self) -> &mut [T; N] { + self + } + + #[inline] + fn from_core_array(arr: [T; N]) -> Self { + arr + } + + #[inline] + fn ref_from_core_array(array_ref: &[T; N]) -> &Self { + array_ref + } + + #[inline] + fn ref_from_mut_core_array(array_ref: &mut [T; N]) -> &mut Self { + array_ref + } + + #[inline] + fn map_to_core_array(self, f: F) -> [U; N] + where + F: FnMut(T) -> U, + { + self.map(f) + } +} + /// Slice operations which don't have access to a const generic array size. pub trait SliceOps: AsRef<[T]>