Skip to content

Commit 821b866

Browse files
committed
rustdoc: small typenum tutorial
Adds a small crash course on typenum in the toplevel rustdoc, especially describing how `hybrid-array` leverages `typenum` via the `ArraySize` trait.
1 parent e704844 commit 821b866

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
//! let arr: Array<u8, U4> = Array([1, 2, 3, 4]);
4848
//! ```
4949
//!
50+
//! ### About [`typenum`]
51+
//!
52+
//! The [`typenum`] crate provides a type-level implementation of numbers and arithmetic operations.
53+
//!
54+
//! While [`typenum`] can be used to express arbitrary integers using the type system, the
55+
//! `hybrid-array` crate is limited to the array sizes in the [`sizes`] module, which have
56+
//! names like [`U0`][`sizes::U0`], [`U1`][`sizes::U1`], [`U2`][`sizes::U2`], [`U3`][`sizes::U3`],
57+
//! etc. All supported sizes will have an impl of [`ArraySize`], which is the trait providing
58+
//! linkage between [`typenum`]-based types and core arrays / const generics.
59+
//!
60+
//! [`ArraySize`] bounds on the [`typenum::Unsigned`] trait, which can be used to obtain integer
61+
//! sizes of arrays via associated constants. For example, to obtain the size of an `ArraySize` as
62+
//! a `usize`, use the associated [`typenum::Unsigned::USIZE`] constant.
63+
//!
5064
//! ## Relationship with `generic-array`
5165
//!
5266
//! `hybrid-array` is directly inspired by the [`generic-array`] crate.

0 commit comments

Comments
 (0)