From 14e75ca51c4cc203244b8a3d07966d2b18ed7770 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 30 Dec 2023 18:34:46 -0700 Subject: [PATCH] hybrid-array: add `ArrayN` type alias (#1017) Adds a type alias for `Array` which uses const generics instead of `typenum`. --- hybrid-array/src/lib.rs | 3 +++ hybrid-array/tests/mod.rs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index 750389f0..e8f2fd69 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -44,6 +44,9 @@ use typenum::{Diff, Sum, Unsigned}; #[cfg(feature = "zeroize")] use zeroize::{Zeroize, ZeroizeOnDrop}; +/// Type alias for [`Array`] which is const generic around a size `N`, ala `[T; N]`. +pub type ArrayN = Array::Size>; + /// Hybrid typenum-based and const generic array type. /// /// Provides the flexibility of typenum-based expressions while also diff --git a/hybrid-array/tests/mod.rs b/hybrid-array/tests/mod.rs index 1ad9adb6..c4b86196 100644 --- a/hybrid-array/tests/mod.rs +++ b/hybrid-array/tests/mod.rs @@ -1,8 +1,11 @@ -use hybrid_array::Array; +use hybrid_array::{Array, ArrayN}; use typenum::{U0, U2, U3, U4, U6, U7}; const EXAMPLE_SLICE: &[u8] = &[1, 2, 3, 4, 5, 6]; +/// Ensure `ArrayN` works as expected. +const _FOO: ArrayN = Array([1, 2, 3, 4]); + #[test] fn clone_from_slice() { let array = Array::::clone_from_slice(EXAMPLE_SLICE);