BoundedInt

Trait BoundedInt 

Source
pub trait BoundedInt:
    Debug
    + Display
    + Default
    + Eq
    + PartialOrd
    + Ord
    + Copy
    + From<bool>
    + TryInto<usize>
    + TryFrom<usize>
    + TryFrom<u8>
    + TryFrom<u16>
    + TryFrom<u32>
    + TryFrom<u64>
    + TryFrom<u128>
    + TryFrom<isize>
    + TryFrom<i8>
    + TryFrom<i16>
    + TryFrom<i32>
    + TryFrom<i64>
    + TryFrom<i128>
where Self: Sized,
{ type Inner; const MIN: Self; const MAX: Self; // Required methods fn into_inner(self) -> Self::Inner; fn as_ref(&self) -> &Self::Inner; fn checked_add(self, rhs: Self) -> Option<Self>; fn checked_sub(self, rhs: Self) -> Option<Self>; // Provided methods fn one() -> Self { ... } fn inc(self) -> Option<Self> { ... } fn dec(self) -> Option<Self> { ... } fn iter() -> BoundedIntIterator<Self> { ... } }
Expand description

Trait for bounded integer types.

It’s implemented by default for all builtin integer types, as they all have a min and a max possible value.

Required Associated Constants§

Source

const MIN: Self

The smallest value that can be represented by this integer type.

Source

const MAX: Self

The largest value that can be represented by this integer type.

Required Associated Types§

Source

type Inner

Type of the inner value if one exists; use Self for fundamental types.

Required Methods§

Source

fn into_inner(self) -> Self::Inner

Extract the inner value.

Source

fn as_ref(&self) -> &Self::Inner

Get a reference to the inner value.

Source

fn checked_add(self, rhs: Self) -> Option<Self>

Checked integer addition.

Source

fn checked_sub(self, rhs: Self) -> Option<Self>

Checked integer subtraction.

Provided Methods§

Source

fn one() -> Self

Return the value 1 of the implementing type.

Source

fn inc(self) -> Option<Self>

Increment value if possible; otherwise return None.

Source

fn dec(self) -> Option<Self>

Decrement value if possible; otherwise return None.

Source

fn iter() -> BoundedIntIterator<Self>

Return an iterator for all values of this BoundedInt type.

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.

Implementations on Foreign Types§

Source§

impl BoundedInt for i8

Source§

const MIN: Self = -128i8

Source§

const MAX: Self = 127i8

Source§

type Inner = i8

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for i16

Source§

const MIN: Self = -32_768i16

Source§

const MAX: Self = 32_767i16

Source§

type Inner = i16

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for i32

Source§

const MIN: Self = -2_147_483_648i32

Source§

const MAX: Self = 2_147_483_647i32

Source§

type Inner = i32

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for i64

Source§

const MIN: Self = -9_223_372_036_854_775_808i64

Source§

const MAX: Self = 9_223_372_036_854_775_807i64

Source§

type Inner = i64

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for i128

Source§

const MIN: Self = -170_141_183_460_469_231_731_687_303_715_884_105_728i128

Source§

const MAX: Self = 170_141_183_460_469_231_731_687_303_715_884_105_727i128

Source§

type Inner = i128

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for isize

Source§

const MIN: Self = -9_223_372_036_854_775_808isize

Source§

const MAX: Self = 9_223_372_036_854_775_807isize

Source§

type Inner = isize

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for u8

Source§

const MIN: Self = 0u8

Source§

const MAX: Self = 255u8

Source§

type Inner = u8

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for u16

Source§

const MIN: Self = 0u16

Source§

const MAX: Self = 65_535u16

Source§

type Inner = u16

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for u32

Source§

const MIN: Self = 0u32

Source§

const MAX: Self = 4_294_967_295u32

Source§

type Inner = u32

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for u64

Source§

const MIN: Self = 0u64

Source§

const MAX: Self = 18_446_744_073_709_551_615u64

Source§

type Inner = u64

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for u128

Source§

const MIN: Self = 0u128

Source§

const MAX: Self = 340_282_366_920_938_463_463_374_607_431_768_211_455u128

Source§

type Inner = u128

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

impl BoundedInt for usize

Source§

const MIN: Self = 0usize

Source§

const MAX: Self = 18_446_744_073_709_551_615usize

Source§

type Inner = usize

Source§

fn into_inner(self) -> Self::Inner

Source§

fn as_ref(&self) -> &Self::Inner

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Implementors§

Source§

impl<const MIN: i8, const MAX: i8> BoundedInt for BoundedI8<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = i8

Source§

impl<const MIN: i16, const MAX: i16> BoundedInt for BoundedI16<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = i16

Source§

impl<const MIN: i32, const MAX: i32> BoundedInt for BoundedI32<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = i32

Source§

impl<const MIN: i64, const MAX: i64> BoundedInt for BoundedI64<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = i64

Source§

impl<const MIN: i128, const MAX: i128> BoundedInt for BoundedI128<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = i128

Source§

impl<const MIN: isize, const MAX: isize> BoundedInt for BoundedIsize<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = isize

Source§

impl<const MIN: u8, const MAX: u8> BoundedInt for BoundedU8<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = u8

Source§

impl<const MIN: u16, const MAX: u16> BoundedInt for BoundedU16<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = u16

Source§

impl<const MIN: u32, const MAX: u32> BoundedInt for BoundedU32<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = u32

Source§

impl<const MIN: u64, const MAX: u64> BoundedInt for BoundedU64<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = u64

Source§

impl<const MIN: u128, const MAX: u128> BoundedInt for BoundedU128<MIN, MAX>

Source§

const MIN: Self

Source§

const MAX: Self

Source§

type Inner = u128