Skip to content

Commit 4cea877

Browse files
committed
Add ConstGenericArray type alias
1 parent 57dc26e commit 4cea877

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ serde = ["dep:serde_core"]
2828
compat-0_14 = ["dep:generic_array-0_14"]
2929

3030
[dependencies]
31-
typenum = { version = "1.17", features = ["const-generics"] }
31+
typenum = { version = "1.19", features = ["const-generics"] }
3232
const-default = { version = "1", optional = true, default-features = false }
3333
serde_core = { version = "1.0", optional = true, default-features = false }
3434
zeroize = { version = "1", optional = true, default-features = false }

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,19 @@ where
283283
/// Associated [`ArrayLength`] for one [`Const<N>`]
284284
///
285285
/// See [`IntoArrayLength`] for more information.
286+
///
287+
/// Note that not all `N` values are valid due to limitations inherent to `typenum` and Rust. You
288+
/// may need to combine [Const] with other typenum operations to get the desired length.
286289
pub type ConstArrayLength<const N: usize> = <Const<N> as IntoArrayLength>::ArrayLength;
287290

291+
/// [`GenericArray`] with a const-generic `usize` length, using the [`ConstArrayLength`] type alias for `N`.
292+
///
293+
/// To construct from a literal array, use [`from_array`](GenericArray::from_array).
294+
///
295+
/// Note that not all `N` values are valid due to limitations inherent to `typenum` and Rust. You
296+
/// may need to combine [Const] with other typenum operations to get the desired length.
297+
pub type ConstGenericArray<T, const N: usize> = GenericArray<T, ConstArrayLength<N>>;
298+
288299
/// Internal type used to generate a struct of appropriate size
289300
#[allow(dead_code)]
290301
#[repr(C)]

0 commit comments

Comments
 (0)