Trait persist_types::Codec[][src]

pub trait Codec: Sized + 'static {
    fn codec_name() -> String;
fn encode<B>(&self, buf: &mut B)
    where
        B: BufMut
;
fn decode<'a>(buf: &'a [u8]) -> Result<Self, String>; }
Expand description

Encoding and decoding operations for a type usable as a persisted key or value.

Required methods

Name of the codec.

This name is stored for the key and value when a stream is first created and the same key and value codec must be used for that stream afterward.

Encode a key or value for permanent storage.

This must perfectly round-trip Self through Codec::decode. If the encode function for this codec ever changes, decode must be able to handle bytes output by all previous versions of encode.

Decode a key or value previous encoded with this codec’s Codec::encode.

This must perfectly round-trip Self through Codec::encode. If the encode function for this codec ever changes, decode must be able to handle bytes output by all previous versions of encode.

It should also gracefully handle data encoded by future versions of encode (likely with an error).

Implementations on Foreign Types

Implementors