Skip to main content

ValueCodec

Trait ValueCodec 

Source
pub trait ValueCodec {
    // Required methods
    fn encode<T: Serialize>(&self, value: &T) -> Result<Vec<u8>, Error>;
    fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> Result<T, Error>;
}
Expand description

Codec for converting typed application values to and from stored bytes.

The core tree stores Vec<u8> leaf values. A ValueCodec is a small reusable adapter that keeps application encode/decode policy next to the schema that owns it.

Required Methods§

Source

fn encode<T: Serialize>(&self, value: &T) -> Result<Vec<u8>, Error>

Encode a typed value into bytes suitable for storing in a tree.

Source

fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> Result<T, Error>

Decode a typed value from bytes read from a tree.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§