pub trait Decodable<'a>: Sized {
// Required method
fn decode(decoder: &mut Decoder<'a>) -> Result<Self>;
// Provided method
fn from_bytes(bytes: &'a [u8]) -> Result<Self> { ... }
}Expand description
Decoding trait.
Decode out of decoder, which essentially is a slice of bytes.
One way to implement this trait is to implement TryFrom<TaggedSlice<'_>, Error = Error>.
Required Methods§
Provided Methods§
Sourcefn from_bytes(bytes: &'a [u8]) -> Result<Self>
fn from_bytes(bytes: &'a [u8]) -> Result<Self>
Parse Self from the provided byte slice.
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.
Implementations on Foreign Types§
Source§impl<'a, T> Decodable<'a> for Option<T>
This implementation is quite gotcha-y, since only one byte is peeked.
impl<'a, T> Decodable<'a> for Option<T>
This implementation is quite gotcha-y, since only one byte is peeked.
It should evaluate to the desired tag via Tag::try_from(byte)?.