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§
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 Associated Types§
Required Methods§
Sourcefn from_le_bytes(bytes: Self::Bytes) -> Self
fn from_le_bytes(bytes: Self::Bytes) -> Self
Create a value of this type from its representation as a byte array in little endian.
Sourcefn from_be_bytes(bytes: Self::Bytes) -> Self
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§
Sourcefn from_bytes(bytes: Self::Bytes) -> Self
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.
Sourcefn from_ne_bytes(bytes: Self::Bytes) -> Self
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.
Sourcefn read_packed<R: Read>(reader: &mut R) -> Result<Self>
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.