pub trait ByteStruct: ByteStructLen {
// Required methods
fn write_bytes(&self, bytes: &mut [u8]);
fn read_bytes(bytes: &[u8]) -> Self;
}
Expand description
A data structure that can be packed into or unpacked from raw bytes.
This trait can be derived by
#[derive(ByteStruct)]
.
One can implement this trait for custom types in order to pack or unpack an object in a special way.
Required Methods§
Sourcefn write_bytes(&self, bytes: &mut [u8])
fn write_bytes(&self, bytes: &mut [u8])
Packs the struct into raw bytes and write to a slice
Sourcefn read_bytes(bytes: &[u8]) -> Self
fn read_bytes(bytes: &[u8]) -> Self
Unpacks raw bytes from a slice into a new struct
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.