pub trait Unpackable: Sized {
type Error: From<Error>;
// Required methods
fn unpack(buf: &[u8]) -> Result<(usize, Self), Self::Error>;
fn unpack_iter<I>(bytes: I) -> Result<(usize, Self), Self::Error>
where I: IntoIterator<Item = u8>;
}Expand description
An unpackable type.
It provides two methods of deserialization: via slices of bytes and iterators.
Slices of bytes are more performant than iterators, but they require the bytes to be eagerly
loaded. If a lazy load deserialization is needed, then use unpack_iter.
Required Associated Types§
Required Methods§
Sourcefn unpack(buf: &[u8]) -> Result<(usize, Self), Self::Error>
fn unpack(buf: &[u8]) -> Result<(usize, Self), Self::Error>
Unpacks a value from the buffer, returning the deserialized value and the amount of read bytes.
Sourcefn unpack_iter<I>(bytes: I) -> Result<(usize, Self), Self::Error>where
I: IntoIterator<Item = u8>,
fn unpack_iter<I>(bytes: I) -> Result<(usize, Self), Self::Error>where
I: IntoIterator<Item = u8>,
Unpacks a value from an iterator of bytes, returning the deserialized value and the amount of read bytes.
This should be used only if lazy load is required. Unpackable::unpack outperforms iterators with a large margin.
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.