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", so this trait is not object safe.

Implementors§

Source§

impl ConstInteger for ConstUsize<0>

Source§

impl ConstInteger for ConstUsize<1>

Source§

const VALUE: usize = 1usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 1]

Source§

type CopyArrayOf<T: Copy> = [T; 1]

Source§

impl ConstInteger for ConstUsize<2>

Source§

const VALUE: usize = 2usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 2]

Source§

type CopyArrayOf<T: Copy> = [T; 2]

Source§

impl ConstInteger for ConstUsize<3>

Source§

const VALUE: usize = 3usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 3]

Source§

type CopyArrayOf<T: Copy> = [T; 3]

Source§

impl ConstInteger for ConstUsize<4>

Source§

const VALUE: usize = 4usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 4]

Source§

type CopyArrayOf<T: Copy> = [T; 4]

Source§

impl ConstInteger for ConstUsize<5>

Source§

const VALUE: usize = 5usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 5]

Source§

type CopyArrayOf<T: Copy> = [T; 5]

Source§

impl ConstInteger for ConstUsize<6>

Source§

const VALUE: usize = 6usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 6]

Source§

type CopyArrayOf<T: Copy> = [T; 6]

Source§

impl ConstInteger for ConstUsize<7>

Source§

const VALUE: usize = 7usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 7]

Source§

type CopyArrayOf<T: Copy> = [T; 7]

Source§

impl ConstInteger for ConstUsize<8>

Source§

const VALUE: usize = 8usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 8]

Source§

type CopyArrayOf<T: Copy> = [T; 8]

Source§

impl ConstInteger for ConstUsize<9>

Source§

impl ConstInteger for ConstUsize<63>

Source§

impl ConstInteger for ConstUsize<64>

Source§

const VALUE: usize = 64usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 64]

Source§

type CopyArrayOf<T: Copy> = [T; 64]

Source§

impl ConstInteger for ConstUsize<65>

Source§

impl ConstInteger for ConstUsize<127>

Source§

impl ConstInteger for ConstUsize<128>

Source§

const VALUE: usize = 128usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 128]

Source§

type CopyArrayOf<T: Copy> = [T; 128]

Source§

impl ConstInteger for ConstUsize<129>

Source§

impl ConstInteger for ConstUsize<255>

Source§

impl ConstInteger for ConstUsize<256>

Source§

const VALUE: usize = 256usize

Source§

const DEFAULT: Self

Source§

type Dec = ConstUsize<{$i-1}>

Source§

type SatDec = ConstUsize<{$i-1}>

Source§

type Inc = ConstUsize<{$i+1}>

Source§

type ArrayOf<T> = [T; 256]

Source§

type CopyArrayOf<T: Copy> = [T; 256]

Source§

impl ConstInteger for ConstUsize<257>

Source§

impl ConstInteger for ConstUsize<MAX>