Trait typerat::Integer

source ·
pub trait Integer: Integer + Sealed { }
Expand description

Type-level integers.

§Examples

This trait is basically implemented for types that implement typenum’s Integer.

use typerat::*;
use typenum::{PInt, UInt, UTerm};

fn to_i8_typenum<I: typenum::Integer>() -> i8 {
    I::to_i8()
}

fn to_i8_typerat<I: Integer>() -> i8 {
    I::to_i8()
}

assert_eq!(to_i8_typenum::<Z0>(), 0_i8);
assert_eq!(to_i8_typerat::<Z0>(), 0_i8);

assert_eq!(to_i8_typenum::<P1>(), 1_i8);
assert_eq!(to_i8_typerat::<P1>(), 1_i8);

assert_eq!(to_i8_typenum::<N1>(), -1_i8);
assert_eq!(to_i8_typerat::<N1>(), -1_i8);

Unlike typenum, compile time unsigned integers with leading zeros are not allowed.

assert_eq!(to_i8_typenum::<PInt<UInt<UTerm, B0>>>(), 0_i8);
assert_eq!(to_i8_typerat::<PInt<UInt<UTerm, B0>>>(), 0_i8);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Integer for Z0

source§

impl<U> Integer for NInt<U>
where U: NonZeroUnsigned,

source§

impl<U> Integer for PInt<U>
where U: NonZeroUnsigned,

Implementors§