Skip to main content

ConstInteger

Trait ConstInteger 

Source
pub trait ConstInteger:
    Default
    + Copy
    + Eq
    + Debug
    + 'static {
    type SatDec: ConstInteger;
    type Dec: ConstInteger;
    type Inc: ConstInteger;
    type ArrayOf<T>: ConstArray<Item = T, Cap = Self>;
    type CopyArrayOf<T: Copy>: ConstArray<Item = T, Cap = Self, DecArray: Copy> + Copy;

    const VALUE: usize;
    const DEFAULT: Self;

    // Provided methods
    fn value(self) -> usize { ... }
    fn sat_dec(self) -> Self::Dec { ... }
    fn dec(self) -> Self::Dec { ... }
    fn inc(self) -> Self::Inc { ... }
}
Expand description

Ala C++ integral_constant.

We need this machinery to fight against Rust’s half-baked const evaluation. With this, we can do const {Self::N+1} in stable rust.

Required Associated Constants§

Source

const VALUE: usize

Source

const DEFAULT: Self

const Default::default()

Required Associated Types§

Source

type SatDec: ConstInteger

Saturating decrement

Source

type Dec: ConstInteger

Source

type Inc: ConstInteger

Source

type ArrayOf<T>: ConstArray<Item = T, Cap = Self>

[T; Self::N]

Source

type CopyArrayOf<T: Copy>: ConstArray<Item = T, Cap = Self, DecArray: Copy> + Copy

Same as Self::ArrayOf, but with additional type bounds.

N.B. We can’t just forward Copy for ArrayOf if T: Copy in Rust.

Provided Methods§

Source

fn value(self) -> usize

Source

fn sat_dec(self) -> Self::Dec

Saturating decrement

Source

fn dec(self) -> Self::Dec

Source

fn inc(self) -> Self::Inc

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ConstInteger for ConstUsize<0>

Source§

impl ConstInteger for ConstUsize<1>

Source§

impl ConstInteger for ConstUsize<2>

Source§

impl ConstInteger for ConstUsize<3>

Source§

impl ConstInteger for ConstUsize<4>

Source§

impl ConstInteger for ConstUsize<5>

Source§

impl ConstInteger for ConstUsize<6>

Source§

impl ConstInteger for ConstUsize<7>

Source§

impl ConstInteger for ConstUsize<8>

Source§

impl ConstInteger for ConstUsize<9>

Source§

impl ConstInteger for ConstUsize<63>

Source§

impl ConstInteger for ConstUsize<64>

Source§

impl ConstInteger for ConstUsize<65>

Source§

impl ConstInteger for ConstUsize<127>

Source§

impl ConstInteger for ConstUsize<128>

Source§

impl ConstInteger for ConstUsize<129>

Source§

impl ConstInteger for ConstUsize<255>

Source§

impl ConstInteger for ConstUsize<256>

Source§

impl ConstInteger for ConstUsize<257>

Source§

impl ConstInteger for ConstUsize<MAX>