Trait Encode

Source
pub trait Encode<T> {
    type Error;

    // Required method
    fn encode(obj: &T) -> Result<Vec<u8>, Self::Error>;
}
Expand description

Encode trait for your own encoding method.

Example:

use bincode_2::{error::EncodeError,serde::encode_to_vec, config::standard};
use serde::Serialize;
pub struct Bincode;

impl<T: Serialize> native_model::Encode<T> for Bincode {
    type Error = EncodeError;
    fn encode(obj: &T) -> Result<Vec<u8>, EncodeError> {
        Ok(encode_to_vec(&obj, standard())?)
    }
}

Required Associated Types§

Required Methods§

Source

fn encode(obj: &T) -> Result<Vec<u8>, Self::Error>

Encodes a T type into a series of bytes.

§Errors

The errors returned from this function depend on the trait implementor (the serializer), i.e. bincode_2.

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§