Module libp2p::multiaddr::multihash::typenum [−][src]
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::{N4, Integer}; 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.
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::{Sum, Integer, 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
array | A type-level array of type-level numbers. |
bit | Type-level bits. |
consts | Type aliases for many constants. |
int | Type-level signed integers. |
marker_traits | All of the marker traits used in typenum. |
operator_aliases | Aliases for the type operators used in this crate.
Their purpose is to increase the ergonomics of performing operations on the types defined
here. For even more ergonomics, consider using the |
type_operators | Useful type operators that are not defined in |
uint | Type-level unsigned integers. |
Macros
assert_type | Asserts that a type is |
assert_type_eq | Asserts that two types are the same. |
cmp | Deprecated A convenience macro for comparing type numbers. Use |
op | Convenient type operations. |
tarr | Create a new type-level arrray. Only usable on Rust 1.13.0 or newer. |
Structs
ATerm | The terminating type for type arrays. |
B0 | The type-level bit 0. |
B1 | The type-level bit 1. |
Equal | A potential output from |
Greater | A potential output from |
Less | A potential output from |
NInt | Type-level signed integers with negative sign. |
PInt | Type-level signed integers with positive sign. |
TArr |
|
UInt |
|
UTerm | The terminating type for |
Z0 | The type-level signed integer 0. |
Traits
Abs | A type operator that returns the absolute value. |
Bit | The marker trait for compile time bits. |
Cmp | A type operator for comparing |
Gcd | A type operator that computes the greatest common divisor of |
Integer | The marker trait for compile time signed integers. |
IsEqual | A type operator that returns |
IsGreater | A type operator that returns |
IsGreaterOrEqual | A type operator that returns |
IsLess | A type operator that returns |
IsLessOrEqual | A type operator that returns |
IsNotEqual | A type operator that returns |
Len | A type operator that gives the length of an |
Logarithm2 | A type operator for taking the integer binary logarithm of |
Max | A type operator that returns the maximum of |
Min | A type operator that returns the minimum of |
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 |
PartialDiv | Division as a partial function. This type operator performs division just as |
Pow | A type operator that provides exponentiation by repeated squaring. |
PowerOfTwo | The marker trait for type-level numbers which are a power of two. |
Same | A type operator that ensures that |
SquareRoot | A type operator for taking the integer square root of |
TypeArray | The marker trait for type-level arrays of type-level numbers. |
Unsigned | The marker trait for compile time unsigned integers. |