pub trait VersionedCodec: Sized {
// Required methods
fn decode_version(version: u8, body: &[u8]) -> Result<Self, CodecError>;
fn encode_version(&self, version: u8) -> Result<Vec<u8>, CodecError>;
}Expand description
A type whose persisted and on-wire representation is versioned.
decode_version up-converts an older layout into the current in-memory type;
encode_version down-converts the current type into the layout of a given
(possibly older) version. Implementors typically match on the version,
routing to a per-version struct via decode_postcard_exact /
encode_postcard and a From conversion. Both methods operate on the
bare body (the bytes after the version prefix); framing is handled by
encode_framed / decode_framed.
Required Methods§
Sourcefn decode_version(version: u8, body: &[u8]) -> Result<Self, CodecError>
fn decode_version(version: u8, body: &[u8]) -> Result<Self, CodecError>
Decode a body known to be version into the current type.
Sourcefn encode_version(&self, version: u8) -> Result<Vec<u8>, CodecError>
fn encode_version(&self, version: u8) -> Result<Vec<u8>, CodecError>
Encode self as the body layout of version.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".