Skip to content

Commit 37dc6ae

Browse files
committed
Add associated len method
1 parent fb7f25c commit 37dc6ae

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,15 @@ where
667667
}
668668

669669
impl<T, N: ArrayLength> GenericArray<T, N> {
670+
/// Returns the number of elements in the array.
671+
///
672+
/// Equivalent to [`<N as Unsigned>::USIZE`](typenum::Unsigned) where `N` is the array length.
673+
///
674+
/// Useful for when only a type alias is available.
675+
pub const fn len() -> usize {
676+
N::USIZE
677+
}
678+
670679
/// Extracts a slice containing the entire array.
671680
#[inline(always)]
672681
pub const fn as_slice(&self) -> &[T] {

0 commit comments

Comments
 (0)