Trait persist_types::Codec[][src]

pub trait Codec: Sized + 'static {
    fn codec_name() -> &'static str;
fn size_hint(&self) -> usize;
fn encode<E: for<'a> Extend<&'a u8>>(&self, buf: &mut E);
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.

A hint of the encoded size of self.

No correctness guarantees are made about the return value of this function, it’s used purely to pre-size buffers.

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