Strong aliases for typenum
, powered by const generics. Makes compilation errors more readable.
typenum
defines convenient type aliases for frequently used numbers.
Unfortunately, rustc
& rust-analyzer
expand them into their full binary representation, e. g. typenum::U10
is expanded to this:
pub type U10 = UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>;
For bigger numbers it's even longer. There's rust-lang/rust-analyzer#1666, which will hopefully solve the problem someday.
typenum_alias
aims to provide a temporary solution which works on stable Rust using only min_const_generics
.
typenum_alias
defines struct Const<const N: i32>
, trait ToTypenum
& trait ToConst
. Arithmetical operations are implemented for Const<N>
in the following way:
Const<N>
is converted toPInt
,NInt
orZ0
typenum
performs the calculations- The result is converted back to
Const<N>
Thanks to this technique, UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>
becomes just Const<10_i32>
.
You can shorten it even more to Const<10>
either by using latest nightly, which already contains the fix
(rust-lang/rust#99393), or by waiting for 1.64.0
stable release of Rust.