funty

Trait Numeric

Source
pub trait Numeric:
    Fundamental
    + Product<Self>
    + for<'a> Product<&'a Self>
    + Sum<Self>
    + for<'a> Sum<&'a Self>
    + Add<Self, Output = Self>
    + for<'a> Add<&'a Self, Output = Self>
    + AddAssign<Self>
    + for<'a> AddAssign<&'a Self>
    + Sub<Self, Output = Self>
    + for<'a> Sub<&'a Self, Output = Self>
    + SubAssign<Self>
    + for<'a> SubAssign<&'a Self>
    + Mul<Self, Output = Self>
    + for<'a> Mul<&'a Self, Output = Self>
    + MulAssign<Self>
    + for<'a> MulAssign<&'a Self>
    + Div<Self, Output = Self>
    + for<'a> Div<&'a Self, Output = Self>
    + DivAssign<Self>
    + for<'a> DivAssign<&'a Self>
    + Rem<Self, Output = Self>
    + for<'a> Rem<&'a Self, Output = Self>
    + RemAssign<Self>
    + for<'a> RemAssign<&'a Self> {
    type Bytes;

    // Required methods
    fn to_be_bytes(self) -> Self::Bytes;
    fn to_le_bytes(self) -> Self::Bytes;
    fn to_ne_bytes(self) -> Self::Bytes;
    fn from_be_bytes(bytes: Self::Bytes) -> Self;
    fn from_le_bytes(bytes: Self::Bytes) -> Self;
    fn from_ne_bytes(bytes: Self::Bytes) -> Self;
}
Expand description

Declare that a type is an abstract number.

This unifies all of the signed-integer, unsigned-integer, and floating-point types.

Required Associated Types§

Source

type Bytes

The [u8; N] byte array that stores values of Self.

Required Methods§

Source

fn to_be_bytes(self) -> Self::Bytes

Return the memory representation of this number as a byte array in big-endian (network) byte order.

Source

fn to_le_bytes(self) -> Self::Bytes

Return the memory representation of this number as a byte array in little-endian byte order.

Source

fn to_ne_bytes(self) -> Self::Bytes

Return the memory representation of this number as a byte array in native byte order.

Source

fn from_be_bytes(bytes: Self::Bytes) -> Self

Create a numeric value from its representation as a byte array in big endian.

Source

fn from_le_bytes(bytes: Self::Bytes) -> Self

Create a numeric value from its representation as a byte array in little endian.

Source

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Create a numeric value from its memory representation as a byte array in native endianness.

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 Numeric for f32

Source§

type Bytes = [u8; 4]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for f64

Source§

type Bytes = [u8; 8]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for i8

Source§

type Bytes = [u8; 1]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for i16

Source§

type Bytes = [u8; 2]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for i32

Source§

type Bytes = [u8; 4]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for i64

Source§

type Bytes = [u8; 8]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for i128

Source§

type Bytes = [u8; 16]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for isize

Source§

type Bytes = [u8; 8]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for u8

Source§

type Bytes = [u8; 1]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for u16

Source§

type Bytes = [u8; 2]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for u32

Source§

type Bytes = [u8; 4]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for u64

Source§

type Bytes = [u8; 8]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for u128

Source§

type Bytes = [u8; 16]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

impl Numeric for usize

Source§

type Bytes = [u8; 8]

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Implementors§