pub trait Encoding: Sized {
type Repr: AsRef<[u8]> + AsMut<[u8]> + Clone + Sized + for<'a> TryFrom<&'a [u8], Error: Error>;
// Required methods
fn from_be_bytes(bytes: Self::Repr) -> Self;
fn from_le_bytes(bytes: Self::Repr) -> Self;
fn to_be_bytes(&self) -> Self::Repr;
fn to_le_bytes(&self) -> Self::Repr;
// Provided methods
fn from_bytes(bytes: Self::Repr, byte_order: ByteOrder) -> Self { ... }
fn from_be_slice_truncated(bytes: &[u8], bits_precision: u32) -> Self { ... }
fn from_le_slice_truncated(bytes: &[u8], bits_precision: u32) -> Self { ... }
fn from_slice_truncated(
bytes: &[u8],
bits_precision: u32,
byte_order: ByteOrder,
) -> Self { ... }
fn to_bytes(&self, byte_order: ByteOrder) -> Self::Repr { ... }
}Expand description
Encoding support.
Required Associated Types§
Required Methods§
Sourcefn from_be_bytes(bytes: Self::Repr) -> Self
fn from_be_bytes(bytes: Self::Repr) -> Self
Decode from big endian bytes.
Sourcefn from_le_bytes(bytes: Self::Repr) -> Self
fn from_le_bytes(bytes: Self::Repr) -> Self
Decode from little endian bytes.
Sourcefn to_be_bytes(&self) -> Self::Repr
fn to_be_bytes(&self) -> Self::Repr
Encode to big endian bytes.
Sourcefn to_le_bytes(&self) -> Self::Repr
fn to_le_bytes(&self) -> Self::Repr
Encode to little endian bytes.
Provided Methods§
Sourcefn from_bytes(bytes: Self::Repr, byte_order: ByteOrder) -> Self
fn from_bytes(bytes: Self::Repr, byte_order: ByteOrder) -> Self
Decode from bytes using the specified ByteOrder.
Sourcefn from_be_slice_truncated(bytes: &[u8], bits_precision: u32) -> Self
fn from_be_slice_truncated(bytes: &[u8], bits_precision: u32) -> Self
Decode from the provided big endian bytes, truncating to the least significant bits in the
event the given amount of data exceeds bits_precision.
Implementations may panic if bits_precision exceeds their underlying size.
Sourcefn from_le_slice_truncated(bytes: &[u8], bits_precision: u32) -> Self
fn from_le_slice_truncated(bytes: &[u8], bits_precision: u32) -> Self
Decode from the provided little endian bytes, truncating to the least significant bits in
the event the given amount of data exceeds bits_precision.
Implementations may panic if bits_precision exceeds their underlying size.
Sourcefn from_slice_truncated(
bytes: &[u8],
bits_precision: u32,
byte_order: ByteOrder,
) -> Self
fn from_slice_truncated( bytes: &[u8], bits_precision: u32, byte_order: ByteOrder, ) -> Self
Decode from the provided bytes, interpreting them using the specified ByteOrder,
truncating to the least significant bits in the event the given amount of data exceeds
bits_precision.
Implementations may panic if bits_precision exceeds their underlying size.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".