pub trait Format<'a, T>: Send + Sync {
    type Error: From<Error> + Debug + Display;

    // Required method
    fn serialize_into<W>(&self, value: &T, writer: W) -> Result<(), Self::Error>
       where W: Write;

    // Provided methods
    fn serialized_size(&self, value: &T) -> Result<Option<usize>, Self::Error> { ... }
    fn serialize(&self, value: &T) -> Result<Vec<u8>, Self::Error> { ... }
}
Expand description

A serialization format.

Required Associated Types§

type Error: From<Error> + Debug + Display

The error type this format produces.

Required Methods§

fn serialize_into<W>(&self, value: &T, writer: W) -> Result<(), Self::Error>
where W: Write,

Serialize value into writer.

Provided Methods§

fn serialized_size(&self, value: &T) -> Result<Option<usize>, Self::Error>

Return the number of bytes value will need to be serialized, or None if pre-measuring is not implemented for this format.

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

Serialize value into a Vec<u8>.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, T> Format<'a, T> for KeyFormat
where T: KeyEncoding,

§

type Error = Error

§

impl<'a, T> Format<'a, T> for Pot
where T: Serialize,

§

type Error = Error