Trait BitEndian

Source
pub trait BitEndian<const N: usize> {
    // Required methods
    fn to_le_bytes(self) -> [u8; N];
    fn to_be_bytes(self) -> [u8; N];
    fn to_ne_bytes(self) -> [u8; N];
    fn from_le_bytes(bytes: [u8; N]) -> Self;
    fn from_be_bytes(bytes: [u8; N]) -> Self;
    fn from_ne_bytes(bytes: [u8; N]) -> Self;

    // Provided methods
    fn to_bytes_endian(self, endian: Endian) -> [u8; N]
       where Self: Sized { ... }
    fn from_bytes_endian(bytes: [u8; N], endian: Endian) -> Self
       where Self: Sized { ... }
}
Expand description

A type that can be infallibly written to or read from an array in an endian-dependent manner.

This trait does not provide to_le etc., since they can be found in num::Primint.

See the module documentation for usage examples.

Required Methods§

Source

fn to_le_bytes(self) -> [u8; N]

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

Source

fn to_be_bytes(self) -> [u8; N]

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

Source

fn to_ne_bytes(self) -> [u8; N]

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

As the target platform’s native endianness is used, portable code should use Self::to_be_bytes or Self::to_le_bytes, as appropriate, instead.

Source

fn from_le_bytes(bytes: [u8; N]) -> Self

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

Source

fn from_be_bytes(bytes: [u8; N]) -> Self

Create a native endian integer value from its representation as a byte array in big (network) endian.

Source

fn from_ne_bytes(bytes: [u8; N]) -> Self

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

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

Provided Methods§

Source

fn to_bytes_endian(self, endian: Endian) -> [u8; N]
where Self: Sized,

Delegates to the appropriate method according to a run-time endianness.

Source

fn from_bytes_endian(bytes: [u8; N], endian: Endian) -> Self
where Self: Sized,

Delegates to the appropriate method according to a run-time 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 BitEndian<1> for i8

Source§

fn to_le_bytes(self) -> [u8; 1]

Source§

fn to_be_bytes(self) -> [u8; 1]

Source§

fn to_ne_bytes(self) -> [u8; 1]

Source§

fn from_le_bytes(bytes: [u8; 1]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 1]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 1]) -> Self

Source§

impl BitEndian<1> for u8

Source§

fn to_le_bytes(self) -> [u8; 1]

Source§

fn to_be_bytes(self) -> [u8; 1]

Source§

fn to_ne_bytes(self) -> [u8; 1]

Source§

fn from_le_bytes(bytes: [u8; 1]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 1]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 1]) -> Self

Source§

impl BitEndian<2> for i16

Source§

fn to_le_bytes(self) -> [u8; 2]

Source§

fn to_be_bytes(self) -> [u8; 2]

Source§

fn to_ne_bytes(self) -> [u8; 2]

Source§

fn from_le_bytes(bytes: [u8; 2]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 2]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 2]) -> Self

Source§

impl BitEndian<2> for u16

Source§

fn to_le_bytes(self) -> [u8; 2]

Source§

fn to_be_bytes(self) -> [u8; 2]

Source§

fn to_ne_bytes(self) -> [u8; 2]

Source§

fn from_le_bytes(bytes: [u8; 2]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 2]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 2]) -> Self

Source§

impl BitEndian<4> for f32

Source§

fn to_le_bytes(self) -> [u8; 4]

Source§

fn to_be_bytes(self) -> [u8; 4]

Source§

fn to_ne_bytes(self) -> [u8; 4]

Source§

fn from_le_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 4]) -> Self

Source§

impl BitEndian<4> for i32

Source§

fn to_le_bytes(self) -> [u8; 4]

Source§

fn to_be_bytes(self) -> [u8; 4]

Source§

fn to_ne_bytes(self) -> [u8; 4]

Source§

fn from_le_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 4]) -> Self

Source§

impl BitEndian<4> for u32

Source§

fn to_le_bytes(self) -> [u8; 4]

Source§

fn to_be_bytes(self) -> [u8; 4]

Source§

fn to_ne_bytes(self) -> [u8; 4]

Source§

fn from_le_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 4]) -> Self

Source§

impl BitEndian<8> for f64

Source§

fn to_le_bytes(self) -> [u8; 8]

Source§

fn to_be_bytes(self) -> [u8; 8]

Source§

fn to_ne_bytes(self) -> [u8; 8]

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 8]) -> Self

Source§

impl BitEndian<8> for i64

Source§

fn to_le_bytes(self) -> [u8; 8]

Source§

fn to_be_bytes(self) -> [u8; 8]

Source§

fn to_ne_bytes(self) -> [u8; 8]

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 8]) -> Self

Source§

impl BitEndian<8> for isize

Source§

fn to_le_bytes(self) -> [u8; 8]

Source§

fn to_be_bytes(self) -> [u8; 8]

Source§

fn to_ne_bytes(self) -> [u8; 8]

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 8]) -> Self

Source§

impl BitEndian<8> for u64

Source§

fn to_le_bytes(self) -> [u8; 8]

Source§

fn to_be_bytes(self) -> [u8; 8]

Source§

fn to_ne_bytes(self) -> [u8; 8]

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 8]) -> Self

Source§

impl BitEndian<8> for usize

Source§

fn to_le_bytes(self) -> [u8; 8]

Source§

fn to_be_bytes(self) -> [u8; 8]

Source§

fn to_ne_bytes(self) -> [u8; 8]

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 8]) -> Self

Source§

impl BitEndian<16> for i128

Source§

fn to_le_bytes(self) -> [u8; 16]

Source§

fn to_be_bytes(self) -> [u8; 16]

Source§

fn to_ne_bytes(self) -> [u8; 16]

Source§

fn from_le_bytes(bytes: [u8; 16]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 16]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 16]) -> Self

Source§

impl BitEndian<16> for u128

Source§

fn to_le_bytes(self) -> [u8; 16]

Source§

fn to_be_bytes(self) -> [u8; 16]

Source§

fn to_ne_bytes(self) -> [u8; 16]

Source§

fn from_le_bytes(bytes: [u8; 16]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 16]) -> Self

Source§

fn from_ne_bytes(bytes: [u8; 16]) -> Self

Implementors§