Crate typenum [−] [src]
This crate provides type-level numbers evaluated at compile time.
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,
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 the stdlib have been used, but their attached functions have not been implemented.
For example, the Add
trait is implemented for both unsigned and signed integers, but
the add
function is not. As there are never any objects of the types defined here, it
wouldn't make sense to implement it. What is important is its associated type Output
,
which is where the addition happens.
use std::ops::Add; use typenum::consts::{P3, P4}; use typenum::int::Integer; type X = <P3 as Add<P4>>::Output; assert_eq!(<X as Integer>::to_i32(), 7);
Documented in each module is the full list of type operators implemented.
Modules
bit |
Type-level bits. These are rather simple and are used as the building blocks of the other number types in this crate. |
consts |
This module defines aliases for many constants. It is generated by typenum's build script. |
int |
Type-level signed integers. |
uint |
Type-level unsigned integers. |
Structs
Equal |
A potential output from |
Greater |
A potential output from |
Less |
A potential output from |
Traits
Cmp |
A type operator for comparing |
NonZero |
A marker trait to designate that a type is not zero. All number types in this
crate implement |
Ord |
A Marker trait for the types |
Pow |
A type operator that provides exponentiation by repeated squaring. |
Same |
A type operator that ensures that |