Crate typenum

This crate provides type-level numbers evaluated at compile time. It depends only on libcore.

The traits defined or used in this crate are used in a typical manner. They can be divided into two categories: marker traits and type operators.

Many of the marker traits have functions defined, but they all do essentially the same thing: convert a type into its runtime counterpart, and are really just there for debugging. For example,

use typenum::{Integer, N4};

assert_eq!(N4::to_i32(), -4);

Type operators are traits that behave as functions at the type level. These are the meat of this library. Where possible, traits defined in libcore have been used.

For example, the Add trait is implemented for both unsigned and signed integers, where its associated type Output represents the sum of the two integers.

use std::ops::Add;
use typenum::{Integer, P3, P4};

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

In addition, helper aliases are defined for type operators. For example, the above snippet could be replaced with

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

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

Documented in each module is the full list of type operators implemented.

Modules

Structs

Traits

Type Aliases

Macros