pub trait FromBytes<'a>: Sized {
// Required method
fn from_bytes(buf: &mut &'a [u8]) -> FromBytesResult<Self>;
// Provided method
fn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> FromBytesResult<Self> { ... }
}
Expand description
Deserialize a field from a byte buffer
Required Methods§
sourcefn from_bytes(buf: &mut &'a [u8]) -> FromBytesResult<Self>
fn from_bytes(buf: &mut &'a [u8]) -> FromBytesResult<Self>
Read the binary representation of a field and return the parsed representation
Note: the argument is a mutable reference to an immutable slice. While the contents
of the slice cannot be modified, the slice itself can. Every call to from_bytes
consumes
a number of bytes from the beginning of the slice.
Provided Methods§
sourcefn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> FromBytesResult<Self>
fn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> FromBytesResult<Self>
Read the binary representation of a field from a buffer that may or may not exist
The default implementation returns an error when the buffer does not exist, but the blanket
impl for Option<T>
effectively returns Ok(None)
Object Safety§
This trait is not object safe.