pub trait Codec<T> {
type Error;
type Compact;
// Required methods
fn encode(&self, val: &T) -> Result<Self::Compact, Self::Error>;
fn decode(&self, val: &Self::Compact) -> Result<T, Self::Error>;
}Expand description
A trait for converting values between a type T and a more compact or
transport-friendly representation for a Backend. Examples include json
and bytes.
This is useful when you need to serialize/deserialize, compress/expand, or otherwise encode/decode values in a custom format.
By default, a backend doesn’t care about the specific type implementing Codec
but rather the Codec::Compact type. This means if it can accept bytes, you
can use familiar crates such as bincode and rkyv
§Type Parameters
T: The type of value being encoded/decoded.
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".