pub trait ComponentCodec<T> {
// Required methods
fn encode(
&self,
value: &T,
out: &mut Vec<u8>,
) -> Result<(), ComponentCodecError>;
fn decode(&self, input: &[u8]) -> Result<T, ComponentCodecError>;
// Provided method
fn fixed_size(&self) -> Option<usize> { ... }
}Expand description
Typed component codec. Embedders can implement this for their own compact schema and bit-packing formats.
Required Methods§
Sourcefn encode(
&self,
value: &T,
out: &mut Vec<u8>,
) -> Result<(), ComponentCodecError>
fn encode( &self, value: &T, out: &mut Vec<u8>, ) -> Result<(), ComponentCodecError>
Encodes value into out.
Sourcefn decode(&self, input: &[u8]) -> Result<T, ComponentCodecError>
fn decode(&self, input: &[u8]) -> Result<T, ComponentCodecError>
Decodes a value from bytes.
Provided Methods§
Sourcefn fixed_size(&self) -> Option<usize>
fn fixed_size(&self) -> Option<usize>
Fixed encoded size when known.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".