Name Description Size
array.rs A type-level array of type-level numbers. It is not very featureful right now, and should be considered a work in progress. 7793
bit.rs Type-level bits. These are rather simple and are used as the building blocks of the other number types in this crate. **Type operators** implemented: - From `core::ops`: `BitAnd`, `BitOr`, `BitXor`, and `Not`. - From `typenum`: `Same` and `Cmp`. 6616
int.rs Type-level signed integers. Type **operators** implemented: From `core::ops`: `Add`, `Sub`, `Mul`, `Div`, and `Rem`. From `typenum`: `Same`, `Cmp`, and `Pow`. Rather than directly using the structs defined in this module, it is recommended that you import and use the relevant aliases from the [consts](../consts/index.html) module. Note that operators that work on the underlying structure of the number are intentionally not implemented. This is because this implementation of signed integers does *not* use twos-complement, and implementing them would require making arbitrary choices, causing the results of such operators to be difficult to reason about. # Example ```rust use std::ops::{Add, Div, Mul, Rem, Sub}; use typenum::{Integer, N3, P2}; assert_eq!(<N3 as Add<P2>>::Output::to_i32(), -1); assert_eq!(<N3 as Sub<P2>>::Output::to_i32(), -5); assert_eq!(<N3 as Mul<P2>>::Output::to_i32(), -6); assert_eq!(<N3 as Div<P2>>::Output::to_i32(), -1); assert_eq!(<N3 as Rem<P2>>::Output::to_i32(), -1); ``` 32782
lib.rs 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, ```rust 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, 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. ```rust 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 ```rust 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. 5883
marker_traits.rs All of the **marker traits** used in typenum. Note that the definition here for marker traits is slightly different than the conventional one -- we include traits with functions that convert a type to the corresponding value, as well as associated constants that do the same. For example, the `Integer` trait includes the function (among others) `fn to_i32() -> i32` and the associated constant `I32` so that one can do this: ``` use typenum::{Integer, N42}; assert_eq!(-42, N42::to_i32()); assert_eq!(-42, N42::I32); ``` 4853
operator_aliases.rs Aliases for the type operators used in this crate. 5050
private.rs **Ignore me!** This module is for things that are conceptually private but that must be made public for typenum to work correctly. Unless you are working on typenum itself, **there is no need to view anything here**. Certainly don't implement any of the traits here for anything. Just look away. Loooooooooooooooooooooooooooooooooook awaaaaaaaaaaaayyyyyyyyyyyyyyyyyyyyyyyyyyyyy... If you do manage to find something of use in here, please let me know. If you can make a compelling case, it may be moved out of __private. Note: Aliases for private type operators will all be named simply that operator followed by an abbreviated name of its associated type. 14656
type_operators.rs Useful **type operators** that are not defined in `core::ops`. 16946
uint.rs Type-level unsigned integers. **Type operators** implemented: From `::core::ops`: `BitAnd`, `BitOr`, `BitXor`, `Shl`, `Shr`, `Add`, `Sub`, `Mul`, `Div`, and `Rem`. From `typenum`: `Same`, `Cmp`, and `Pow`. Rather than directly using the structs defined in this module, it is recommended that you import and use the relevant aliases from the [consts](../consts/index.html) module. # Example ```rust use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Rem, Shl, Shr, Sub}; use typenum::{Unsigned, U1, U2, U3, U4}; assert_eq!(<U3 as BitAnd<U2>>::Output::to_u32(), 2); assert_eq!(<U3 as BitOr<U4>>::Output::to_u32(), 7); assert_eq!(<U3 as BitXor<U2>>::Output::to_u32(), 1); assert_eq!(<U3 as Shl<U1>>::Output::to_u32(), 6); assert_eq!(<U3 as Shr<U1>>::Output::to_u32(), 1); assert_eq!(<U3 as Add<U2>>::Output::to_u32(), 5); assert_eq!(<U3 as Sub<U2>>::Output::to_u32(), 1); assert_eq!(<U3 as Mul<U2>>::Output::to_u32(), 6); assert_eq!(<U3 as Div<U2>>::Output::to_u32(), 1); assert_eq!(<U3 as Rem<U2>>::Output::to_u32(), 1); ``` 65628