.. /index

typenum

typenum

typenum provides type-level numbers evaluated at compile time, with full arithmetic (Add, Sub, Mul, Div, Pow), comparisons, and bitwise operations. Its op! macro enables ergonomic expressions like op!(U3 + U4). It is the foundation of type-level programming in Rust, underpinning generic-array, dimensioned (compile-time SI/CGS unit checking), and much of the RustCrypto ecosystem.

Why typenum still matters

Rust's const generics can handle basic [T; N] arrays, but they cannot yet do arithmetic in associated type positions — you can't express Array<N> + Array<M> = Array<N+M> with const generics alone. typenum fills this gap with trait-based arithmetic that works today on stable Rust. generic-array bridges the two worlds, and hybrid-array provides a modern transition path.

Related crates

See rust-enum-crates for the full type-level programming landscape.

Linked from

Sources