Skip to content
Compile time numbers in Rust.
Branch: master
Clone or download
paholg Merge pull request #115 from mwhudson/patch-1
round result of (highest as f64).log(2.0)
Latest commit 14a3322 Mar 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
src Implement integer binary logarithm operator Nov 25, 2018
tests
.gitignore
.travis.yml Cleanup Jun 20, 2018
CHANGELOG.md
Cargo.toml
LICENSE
README.md

README.md

crates.io Build Status

Typenum

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.

Importing

While 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, perfoming a glob import.

Example

Here is a trivial example of typenum's use:

use typenum::{Sum, Exp, Integer, N2, P3, P4};

type X = Sum<P3, P4>;
assert_eq!(<X as Integer>::to_i32(), 7);

type Y = Exp<N2, P3>;
assert_eq!(<Y as Integer>::to_i32(), -8);

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.

You can’t perform that action at this time.