bitstream_io

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 our 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§

type Bytes = [u8; 4]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for f64

Source§

type Bytes = [u8; 8]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for i8

Source§

type Bytes = [u8; 1]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for i16

Source§

type Bytes = [u8; 2]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for i32

Source§

type Bytes = [u8; 4]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for i64

Source§

type Bytes = [u8; 8]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for i128

Source§

type Bytes = [u8; 16]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for u8

Source§

type Bytes = [u8; 1]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for u16

Source§

type Bytes = [u8; 2]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for u32

Source§

type Bytes = [u8; 4]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for u64

Source§

type Bytes = [u8; 8]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

impl Primitive for u128

Source§

type Bytes = [u8; 16]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Source§

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

Source§

type Bytes = [u8; N]

Source§

fn buffer() -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

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

Source§

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

Implementors§