pub trait Decode: Sized {
// Required method
fn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError>;
// Provided method
fn get_decoded(bytes: &[u8]) -> Result<Self, CodecError> { ... }
}
Expand description
Describes how to decode an object from a byte sequence.
Required Methods§
Sourcefn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError>
fn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError>
Read and decode an encoded object from bytes
. On success, the decoded value is returned
and bytes
is advanced by the encoded size of the value. On failure, an error is returned
and no further attempt to read from bytes
should be made.
Provided Methods§
Sourcefn get_decoded(bytes: &[u8]) -> Result<Self, CodecError>
fn get_decoded(bytes: &[u8]) -> Result<Self, CodecError>
Convenience method to get a decoded value. Returns an error if Self::decode
fails, or if
there are any bytes left in bytes
after decoding a value.
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.