Skip to content

Commit

Permalink
hybrid-array: add ArrayN type alias (#1017)
Browse files Browse the repository at this point in the history
Adds a type alias for `Array` which uses const generics instead of
`typenum`.
  • Loading branch information
tarcieri committed Dec 31, 2023
1 parent 35e61ad commit 14e75ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, const N: usize> = Array<T, <[T; N] as AssociatedArraySize>::Size>;

/// Hybrid typenum-based and const generic array type.
///
/// Provides the flexibility of typenum-based expressions while also
Expand Down
5 changes: 4 additions & 1 deletion hybrid-array/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -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<u8, 4> = Array([1, 2, 3, 4]);

#[test]
fn clone_from_slice() {
let array = Array::<u8, U6>::clone_from_slice(EXAMPLE_SLICE);
Expand Down

0 comments on commit 14e75ca

Please sign in to comment.