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§
sourcefn to_le_bytes(self) -> [u8; N]
fn to_le_bytes(self) -> [u8; N]
Return the memory representation of this integer as a byte array in little-endian byte order.
sourcefn to_be_bytes(self) -> [u8; N]
fn to_be_bytes(self) -> [u8; N]
Return the memory representation of this integer as a byte array in big-endian (network) byte order.
sourcefn to_ne_bytes(self) -> [u8; N]
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.
sourcefn from_le_bytes(bytes: [u8; N]) -> Self
fn from_le_bytes(bytes: [u8; N]) -> Self
Create a native endian integer value from its representation as a byte array in little endian.
sourcefn from_be_bytes(bytes: [u8; N]) -> Self
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.
sourcefn from_ne_bytes(bytes: [u8; N]) -> Self
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.