pub trait Codec: Sized {
// Required methods
fn write(&self, writer: &mut impl Writer);
fn read(reader: &mut impl Reader) -> Result<Self, Error>;
fn len_encoded(&self) -> usize;
// Provided methods
fn encode(&self) -> Vec<u8> ⓘ { ... }
fn decode(bytes: impl Into<Bytes>) -> Result<Self, Error> { ... }
}
Expand description
Trait for types that can be encoded to and decoded from bytes
Required Methods§
Sourcefn len_encoded(&self) -> usize
fn len_encoded(&self) -> usize
Returns the encoded length of this value.
Provided Methods§
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.