Skip to main content

Format

Trait Format 

Source
pub trait Format<T>: Sized {
    type SerError: Error + Send + Sync + 'static;
    type DeError: Error + Send + Sync + 'static;

    // Required methods
    fn to_bytes(value: &T) -> Result<Vec<u8>, Self::SerError>;
    fn from_bytes(data: Vec<u8>) -> Result<T, Self::DeError>;
}
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).

Required Associated Types§

Source

type SerError: Error + Send + Sync + 'static

Source

type DeError: Error + Send + Sync + 'static

Required Methods§

Source

fn to_bytes(value: &T) -> Result<Vec<u8>, Self::SerError>

Convert data to bytes.

§Errors

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

Source

fn from_bytes(data: Vec<u8>) -> Result<T, Self::DeError>

Convert bytes to data.

§Errors

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

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§

Source§

impl<T: DeserializeOwned + Serialize> Format<T> for Json

Available on crate feature json-format only.
Source§

impl<T: DeserializeOwned + Serialize> Format<T> for Toml

Available on crate feature toml-format only.
Source§

impl<T: Serialize + DeserializeOwned> Format<T> for Bincode

Available on crate feature bincode-format only.