Trait koit::format::Format[][src]

pub trait Format<T>: Sized {
    type Error: Error + Send + Sync + 'static;
    fn to_bytes(value: &T) -> Result<Vec<u8>, Self::Error>;
fn from_bytes(data: Vec<u8>) -> Result<T, Self::Error>; }
Expand description

Trait implementable by format providers.

By implementing this trait, a type becomes a marker for the specified format. That type can then be used for formatting (without instantiating an object of that type).

Associated Types

type Error: Error + Send + Sync + 'static[src]

Loading content...

Required methods

fn to_bytes(value: &T) -> Result<Vec<u8>, Self::Error>[src]

Expand description

Convert data to bytes.

Errors

If the data failed to be encoded by the format, an error variant is returned.

fn from_bytes(data: Vec<u8>) -> Result<T, Self::Error>[src]

Expand description

Convert bytes to data.

Errors

If the bytes failed to be decoded by the format, an error variant is returned.

Loading content...

Implementors

impl<T: DeserializeOwned + Serialize> Format<T> for Json[src]

type Error = Error

fn to_bytes(value: &T) -> Result<Vec<u8>, Self::Error>[src]

fn from_bytes(data: Vec<u8>) -> Result<T, Error>[src]

impl<T: Serialize + DeserializeOwned> Format<T> for Bincode[src]

type Error = Error

fn to_bytes(value: &T) -> Result<Vec<u8>, Self::Error>[src]

fn from_bytes(data: Vec<u8>) -> Result<T, Self::Error>[src]

Loading content...