Format

Trait Format 

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

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

    // 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§

Source

type Error: From<Error> + Debug + Display

The error type this format produces.

Required Methods§

Source

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

Serialize value into writer.

Provided Methods§

Source

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.

Source

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

Serialize value into a Vec<u8>.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§