Skip to main content

NumberLike

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 = Self::NEG_INFINITY

Source§

const MAX: Self = Self::INFINITY

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 = Self::NEG_INFINITY

Source§

const MAX: Self = Self::INFINITY

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

Source§

type Underlying = isize

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 u8

Source§

const MIN: Self = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

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 = Self::MIN

Source§

const MAX: Self = Self::MAX

Source§

type Underlying = usize

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>

Implementors§