Trait packbytes::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.

Required Associated Types§

source

type Bytes: ByteArray

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

Provided Associated Constants§

source

const PREFERS_LE: bool = true

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

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FromBytes for f32

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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 u8

§

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

§

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

§

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

§

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

§

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 ()

§

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

§

type Bytes = [u8; 4]

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]

§

type Bytes = [u8; N]

source§

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

source§

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

Implementors§