pub trait Primitive {
type Bytes: AsRef<[u8]> + AsMut<[u8]>;
// Required methods
fn buffer() -> Self::Bytes;
fn to_be_bytes(self) -> Self::Bytes;
fn to_le_bytes(self) -> Self::Bytes;
fn from_be_bytes(bytes: Self::Bytes) -> Self;
fn from_le_bytes(bytes: Self::Bytes) -> Self;
}
Expand description
A trait intended for simple fixed-length primitives (such as ints and floats) which allows them to be read and written to streams of different endiannesses verbatim.
Required Associated Types§
Required Methods§
Sourcefn to_be_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
Our value in big-endian bytes
Sourcefn to_le_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
Our value in little-endian bytes
Sourcefn from_be_bytes(bytes: Self::Bytes) -> Self
fn from_be_bytes(bytes: Self::Bytes) -> Self
Convert big-endian bytes to our value
Sourcefn from_le_bytes(bytes: Self::Bytes) -> Self
fn from_le_bytes(bytes: Self::Bytes) -> Self
Convert little-endian bytes to our value
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.