FromBytes

Trait FromBytes 

Source
pub trait FromBytes: Sized {
    type Bytes: ByteArray;

    const PREFERS_LE: bool = true;

    // Required methods
    fn from_le_bytes(bytes: Self::Bytes) -> Self;
    fn from_be_bytes(bytes: Self::Bytes) -> Self;

    // Provided methods
    fn from_bytes(bytes: Self::Bytes) -> Self { ... }
    fn from_ne_bytes(bytes: Self::Bytes) -> Self { ... }
    fn read_packed<R: Read>(reader: &mut R) -> Result<Self> { ... }
}
Expand description

Create a value from its representation as a packed stack byte array of a fixed size.

Most times, the method from_bytes should be used, as it ensures consistency by respecting the byte order set by the PREFERS_LE associated constant.

Provided Associated Constants§

Source

const PREFERS_LE: bool = true

Is it preferred to represent this type as bytes in the little endian order?

Required Associated Types§

Source

type Bytes: ByteArray

A byte array which can store a packed representation of this type.

Required Methods§

Source

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

Create a value of this type from its representation as a byte array in little endian.

Source

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

Create a value of this type from its representation as a byte array in big endian.

Provided Methods§

Source

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

Create a value of this type from its representation as a byte array in the preferred byte order, set in the associated constant PREFERS_LE.

Source

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

Create a value of this type from its representation as a byte array in native endian.

As the target platform’s native endianness is used, portable code likely wants to use from_le_bytes or from_be_bytes, as appropriate instead.

Source

fn read_packed<R: Read>(reader: &mut R) -> Result<Self>

Read a byte representation of this type in the preferred byte order (set in the associated constant PREFERS_LE) and create a value of this type from it.

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

Source§

type Bytes = [u8; 4]

Source§

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

Source§

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

Source§

impl FromBytes for f64

Source§

type Bytes = [u8; 8]

Source§

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

Source§

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

Source§

impl FromBytes for i8

Source§

type Bytes = [u8; 1]

Source§

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

Source§

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

Source§

impl FromBytes for i16

Source§

type Bytes = [u8; 2]

Source§

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

Source§

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

Source§

impl FromBytes for i32

Source§

type Bytes = [u8; 4]

Source§

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

Source§

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

Source§

impl FromBytes for i64

Source§

type Bytes = [u8; 8]

Source§

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

Source§

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

Source§

impl FromBytes for i128

Source§

type Bytes = [u8; 16]

Source§

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

Source§

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

Source§

impl FromBytes for isize

Source§

type Bytes = [u8; 8]

Source§

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

Source§

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

Source§

impl FromBytes for u8

Source§

type Bytes = [u8; 1]

Source§

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

Source§

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

Source§

impl FromBytes for u16

Source§

type Bytes = [u8; 2]

Source§

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

Source§

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

Source§

impl FromBytes for u32

Source§

type Bytes = [u8; 4]

Source§

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

Source§

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

Source§

impl FromBytes for u64

Source§

type Bytes = [u8; 8]

Source§

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

Source§

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

Source§

impl FromBytes for u128

Source§

type Bytes = [u8; 16]

Source§

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

Source§

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

Source§

impl FromBytes for ()

Source§

type Bytes = [u8; 0]

Source§

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

Source§

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

Source§

impl FromBytes for usize

Source§

type Bytes = [u8; 8]

Source§

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

Source§

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

Source§

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

Source§

type Bytes = [u8; N]

Source§

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

Source§

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

Implementors§