Typenum is a Rust library for type-level numbers evaluated at compile time. It currently supports bits, unsigned integers, and signed integers.
Typenum depends only on libcore, and so is suitable for use on any platform!
For the full documentation, go here.
typenum is divided into several modules, they are all re-exported
through the crate root, so you can import anything contained herein with
use typenum::whatever;, ignoring the crate structure.
You may also find it useful to treat the
consts module as a prelude,
performing a glob import.
Here is a trivial example of
use ; type X = ; assert_eq!; type Y = ; assert_eq!;
For a non-trivial example of its use, see one of the crates that depends on it. The full list is here. Of note are dimensioned which does compile-time type checking for arbitrary unit systems and generic-array which provides arrays whose length you can generically refer to.
Typenum's error messages aren't great, and can be difficult to parse. The good news is that the fine folks at Auxon have written a tool to help with it. Please take a look at tnfilt.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.