pub trait ToBytes: Sized {
type Bytes: ByteArray;
const PREFERS_LE: bool = true;
// Required methods
fn to_le_bytes(self) -> Self::Bytes;
fn to_be_bytes(self) -> Self::Bytes;
// Provided methods
fn to_bytes(self) -> Self::Bytes { ... }
fn to_ne_bytes(self) -> Self::Bytes { ... }
fn write_packed<W: Write>(self, writer: &mut W) -> Result<usize> { ... }
}Expand description
Pack this type into a stack byte array of a fixed size.
Most times, the method to_bytes should be used, as it ensures consistency by respecting
the byte order set by the PREFERS_LE associated constant.
Required Associated Types§
Provided Associated Constants§
sourceconst PREFERS_LE: bool = true
const PREFERS_LE: bool = true
Is it preferred to represent this type as bytes in the little endian order?
Required Methods§
sourcefn to_le_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
Return the memory representation of this type as a byte array in little endian byte order.
sourcefn to_be_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
Return the memory representation of this type as a byte array in big endian byte order.
Provided Methods§
sourcefn to_bytes(self) -> Self::Bytes
fn to_bytes(self) -> Self::Bytes
Return the memory representation of this type as a byte array in the preferred
byte order, set in the associated constant PREFERS_LE.
sourcefn to_ne_bytes(self) -> Self::Bytes
fn to_ne_bytes(self) -> Self::Bytes
Return the memory representation of this type as a byte array in native endian byte order.
As the target platform’s native endianness is used, portable code likely wants to use
to_le_bytes or to_be_bytes, as appropriate instead.