pub trait Packable {
type Error: Debug;
// Required methods
fn packed_len(&self) -> usize;
fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>;
fn unpack_inner<R: Read + ?Sized, const CHECK: bool>(
reader: &mut R,
) -> Result<Self, Self::Error>
where Self: Sized;
// Provided methods
fn pack_new(&self) -> Vec<u8> ⓘ { ... }
fn unpack<R: Read + ?Sized>(reader: &mut R) -> Result<Self, Self::Error>
where Self: Sized { ... }
fn unpack_unchecked<R: Read + ?Sized>(
reader: &mut R,
) -> Result<Self, Self::Error>
where Self: Sized { ... }
}Expand description
A trait to pack and unpack types to and from bytes.
Required Associated Types§
Required Methods§
Sourcefn packed_len(&self) -> usize
fn packed_len(&self) -> usize
Returns the length of the packed bytes.
Provided Methods§
Sourcefn pack_new(&self) -> Vec<u8> ⓘ
fn pack_new(&self) -> Vec<u8> ⓘ
Packs the instance to bytes and writes them to a newly allocated vector.
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.