Primitive

Trait Primitive 

Source
pub trait Primitive {
    type Bytes: AsRef<[u8]> + AsMut<[u8]>;

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

A trait intended for simple fixed-length primitives (such as ints and floats) which allows them to be read and written to streams of different endiannesses verbatim.

Required Associated Types§

Source

type Bytes: AsRef<[u8]> + AsMut<[u8]>

The raw byte representation of this numeric type

Required Methods§

Source

fn buffer() -> Self::Bytes

An empty buffer of this type’s size

Source

fn to_be_bytes(self) -> Self::Bytes

Our value in big-endian bytes

Source

fn to_le_bytes(self) -> Self::Bytes

Our value in little-endian bytes

Source

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

Convert big-endian bytes to our value

Source

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

Convert little-endian bytes to out value

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

Source§

impl Primitive for f64

Source§

impl Primitive for i8

Source§

impl Primitive for i16

Source§

impl Primitive for i32

Source§

impl Primitive for i64

Source§

impl Primitive for i128

Source§

impl Primitive for u8

Source§

impl Primitive for u16

Source§

impl Primitive for u32

Source§

impl Primitive for u64

Source§

impl Primitive for u128

Source§

impl<const N: usize> Primitive for [u8; N]

Source§

type Bytes = [u8; N]

Source§

fn buffer() -> <[u8; N] as Primitive>::Bytes

Source§

fn to_be_bytes(self) -> <[u8; N] as Primitive>::Bytes

Source§

fn to_le_bytes(self) -> <[u8; N] as Primitive>::Bytes

Source§

fn from_be_bytes(bytes: <[u8; N] as Primitive>::Bytes) -> [u8; N]

Source§

fn from_le_bytes(bytes: <[u8; N] as Primitive>::Bytes) -> [u8; N]

Implementors§