typenum::generic_const_mappings

Type Alias U

Source
pub type U<const N: usize> = <Const<N> as ToUInt>::Output;
Available on crate feature const-generics only.
Expand description

The main mapping from a generic const: usize to a UInt: U<N> is expected to work like UN.

  • It requires the const-generics crate feature to be enabled.

ยงExample

use typenum::*;

assert_type_eq!(U<42>, U42);

This can even be used in a generic const N: usize context, provided the genericity is guarded by a where clause:

use typenum::*;

struct MyStruct<const N: usize>;

trait MyTrait { type AssocType; }

impl<const N: usize> MyTrait
    for MyStruct<N>
where
    Const<N> : ToUInt,
{
    type AssocType = U<N>;
}

assert_type_eq!(<MyStruct<42> as MyTrait>::AssocType, U42);