Decode

Trait Decode 

Source
pub trait Decode<T> {
    type Error;

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

Decode trait for your own decoding method.

Example:

use bincode_2::{error::DecodeError,serde::decode_from_slice, config::standard};
use serde::Deserialize;
pub struct Bincode;

impl<T: for<'a> Deserialize<'a>> native_model::Decode<T> for Bincode {
    type Error = DecodeError;
    fn decode(data: Vec<u8>) -> Result<T, DecodeError> {
        Ok(decode_from_slice(&data, standard())?.0)
    }
}

Required Associated Types§

Required Methods§

Source

fn decode(data: Vec<u8>) -> Result<T, Self::Error>

Decodes a series of bytes back into a T type.

§Errors

The errors returned from this function depend on the trait implementor (the deserializer), 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§

Source§

impl<T: for<'de> Deserialize<'de>> Decode<T> for Bincode