Trait NumberLike

Source
pub trait NumberLike:
    Primitive
    + Copy
    + Default
    + FromStr
    + PartialEq
    + PartialOrd
    + Debug
    + Display
    + Unpin
    + UnwindSafe
    + RefUnwindSafe
    + Send
    + Sync
    + Sized
    + 'static {
    type Underlying: Number;
    type ByteArray: Array<Item = u8>;

    const MIN: Self;
    const MAX: Self;

    // Required methods
    fn to_underlying(self) -> Self::Underlying;
    fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>;
    fn to_bytes(self) -> Self::ByteArray;
    fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>;
    fn to_be_bytes(self) -> Self::ByteArray;
    fn to_le_bytes(self) -> Self::ByteArray;
    fn to_ne_bytes(self) -> Self::ByteArray;
    fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>;
    fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>;
    fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>;
}

Required Associated Constants§

Source

const MIN: Self

Same as the builtin MIN associated constant, except that this is NEG_INFINITY for floats instead of the minimum finite value.

Source

const MAX: Self

Same as the builtin MAX associated constant, except that this is INFINITY for floats instead of the maximum finite value.

Required Associated Types§

Required Methods§

Source

fn to_underlying(self) -> Self::Underlying

Source

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source

fn to_bytes(self) -> Self::ByteArray

Source

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source

fn to_be_bytes(self) -> Self::ByteArray

Source

fn to_le_bytes(self) -> Self::ByteArray

Source

fn to_ne_bytes(self) -> Self::ByteArray

Source

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

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 NumberLike for bool

Source§

const MIN: Self = false

Source§

const MAX: Self = true

Source§

type Underlying = u8

Source§

type ByteArray = [u8; 1]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for char

Source§

const MIN: Self = '\0'

Source§

const MAX: Self = '\u{10ffff}'

Source§

type Underlying = u32

Source§

type ByteArray = [u8; 4]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for f32

Source§

const MIN: Self = -Inf_f32

Source§

const MAX: Self = +Inf_f32

Source§

type Underlying = f32

Source§

type ByteArray = [u8; 4]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for f64

Source§

const MIN: Self = -Inf_f64

Source§

const MAX: Self = +Inf_f64

Source§

type Underlying = f64

Source§

type ByteArray = [u8; 8]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for i8

Source§

const MIN: Self = -128i8

Source§

const MAX: Self = 127i8

Source§

type Underlying = i8

Source§

type ByteArray = [u8; 1]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for i16

Source§

const MIN: Self = -32_768i16

Source§

const MAX: Self = 32_767i16

Source§

type Underlying = i16

Source§

type ByteArray = [u8; 2]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for i32

Source§

const MIN: Self = -2_147_483_648i32

Source§

const MAX: Self = 2_147_483_647i32

Source§

type Underlying = i32

Source§

type ByteArray = [u8; 4]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike 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 Underlying = i64

Source§

type ByteArray = [u8; 8]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike 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 Underlying = i128

Source§

type ByteArray = [u8; 16]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for isize

Source§

const MIN: Self = -2_147_483_648isize

Source§

const MAX: Self = 2_147_483_647isize

Source§

type Underlying = isize

Source§

type ByteArray = [u8; 4]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for u8

Source§

const MIN: Self = 0u8

Source§

const MAX: Self = 255u8

Source§

type Underlying = u8

Source§

type ByteArray = [u8; 1]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for u16

Source§

const MIN: Self = 0u16

Source§

const MAX: Self = 65_535u16

Source§

type Underlying = u16

Source§

type ByteArray = [u8; 2]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for u32

Source§

const MIN: Self = 0u32

Source§

const MAX: Self = 4_294_967_295u32

Source§

type Underlying = u32

Source§

type ByteArray = [u8; 4]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for u64

Source§

const MIN: Self = 0u64

Source§

const MAX: Self = 18_446_744_073_709_551_615u64

Source§

type Underlying = u64

Source§

type ByteArray = [u8; 8]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike 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 Underlying = u128

Source§

type ByteArray = [u8; 16]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

impl NumberLike for usize

Source§

const MIN: Self = 0usize

Source§

const MAX: Self = 4_294_967_295usize

Source§

type Underlying = usize

Source§

type ByteArray = [u8; 4]

Source§

fn to_underlying(self) -> Self::Underlying

Source§

fn try_from_underlying(underlying: Self::Underlying) -> Option<Self>

Source§

fn to_bytes(self) -> Self::ByteArray

Source§

fn try_from_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn to_le_bytes(self) -> Self::ByteArray

Source§

fn to_ne_bytes(self) -> Self::ByteArray

Source§

fn try_from_be_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_le_bytes(bytes: Self::ByteArray) -> Option<Self>

Source§

fn try_from_ne_bytes(bytes: Self::ByteArray) -> Option<Self>

Implementors§