pub trait BeBytes {
// Required methods
fn field_size() -> usize;
fn to_be_bytes(&self) -> Vec<u8> ⓘ;
fn try_from_be_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>
where Self: Sized;
fn to_le_bytes(&self) -> Vec<u8> ⓘ;
fn try_from_le_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>
where Self: Sized;
// Provided methods
fn to_be_bytes_buf(&self) -> Bytes { ... }
fn to_le_bytes_buf(&self) -> Bytes { ... }
fn encode_be_to<B: BufMut>(&self, buf: &mut B) -> Result<(), BeBytesError> { ... }
fn encode_le_to<B: BufMut>(&self, buf: &mut B) -> Result<(), BeBytesError> { ... }
}Required Methods§
fn field_size() -> usize
fn to_be_bytes(&self) -> Vec<u8> ⓘ
Sourcefn try_from_be_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>where
Self: Sized,
fn try_from_be_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>where
Self: Sized,
Try to parse a struct from big-endian bytes
§Errors
Returns BeBytesError::EmptyBuffer if the input slice is empty
Returns BeBytesError::InsufficientData if there aren’t enough bytes to parse all fields
Returns BeBytesError::InvalidDiscriminant if an enum field has an invalid value
Returns BeBytesError::InvalidBitField if a bit field value exceeds its maximum
fn to_le_bytes(&self) -> Vec<u8> ⓘ
Sourcefn try_from_le_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>where
Self: Sized,
fn try_from_le_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>where
Self: Sized,
Try to parse a struct from little-endian bytes
§Errors
Returns BeBytesError::EmptyBuffer if the input slice is empty
Returns BeBytesError::InsufficientData if there aren’t enough bytes to parse all fields
Returns BeBytesError::InvalidDiscriminant if an enum field has an invalid value
Returns BeBytesError::InvalidBitField if a bit field value exceeds its maximum
Provided Methods§
Sourcefn to_be_bytes_buf(&self) -> Bytes
fn to_be_bytes_buf(&self) -> Bytes
Convert to big-endian bytes as a Bytes buffer
Returns a Bytes buffer (now a simple Vec wrapper without reference counting)
Sourcefn to_le_bytes_buf(&self) -> Bytes
fn to_le_bytes_buf(&self) -> Bytes
Convert to little-endian bytes as a Bytes buffer
Returns a Bytes buffer (now a simple Vec wrapper without reference counting)
Sourcefn encode_be_to<B: BufMut>(&self, buf: &mut B) -> Result<(), BeBytesError>
fn encode_be_to<B: BufMut>(&self, buf: &mut B) -> Result<(), BeBytesError>
Encode directly to a buffer in big-endian format
Writes struct data directly to the provided buffer without intermediate allocations.
§Errors
Returns an error if the buffer doesn’t have enough capacity
Sourcefn encode_le_to<B: BufMut>(&self, buf: &mut B) -> Result<(), BeBytesError>
fn encode_le_to<B: BufMut>(&self, buf: &mut B) -> Result<(), BeBytesError>
Encode directly to a buffer in little-endian format
Writes struct data directly to the provided buffer without intermediate allocations.
§Errors
Returns an error if the buffer doesn’t have enough capacity
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.