fuel_core_storage::codec

Trait Encode

Source
pub trait Encode<T: ?Sized> {
    type Encoder<'a>: Encoder
       where T: 'a;

    // Required method
    fn encode(t: &T) -> Self::Encoder<'_>;

    // Provided method
    fn encode_as_value(t: &T) -> Value { ... }
}
Expand description

The trait encodes the type to the bytes and passes it to the Encoder, which stores it and provides a reference to it. That allows gives more flexibility and more performant encoding, allowing the use of slices and arrays instead of vectors in some cases. Since the Encoder returns Cow<[u8]>, it is always possible to take ownership of the serialized value.

Required Associated Types§

Source

type Encoder<'a>: Encoder where T: 'a

The encoder type that stores serialized object.

Required Methods§

Source

fn encode(t: &T) -> Self::Encoder<'_>

Encodes the object to the bytes and passes it to the Encoder.

Provided Methods§

Source

fn encode_as_value(t: &T) -> Value

Returns the serialized object as an Value.

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 Encode<Block> for BlockEncoder

Source§

type Encoder<'a> = [u8; 32]

Source§

impl Encode<Block<Bytes32>> for BlockEncoder

Source§

type Encoder<'a> = [u8; 32]

Source§

impl Encode<u8> for Primitive<{ 1 }>

Source§

type Encoder<'a> = [u8; 1]

Source§

impl Encode<u16> for Primitive<{ 2 }>

Source§

type Encoder<'a> = [u8; 2]

Source§

impl Encode<u32> for Primitive<{ 4 }>

Source§

type Encoder<'a> = [u8; 4]

Source§

impl Encode<u64> for Primitive<{ 8 }>

Source§

type Encoder<'a> = [u8; 8]

Source§

impl Encode<u128> for Primitive<{ 16 }>

Source§

type Encoder<'a> = [u8; 16]

Source§

impl Encode<DaBlockHeight> for Primitive<{ 8 }>

Source§

type Encoder<'a> = [u8; 8]

Source§

impl Encode<UtxoId> for Primitive<{ _ }>

Source§

type Encoder<'a> = [u8; 34]

Source§

impl Encode<BlockHeight> for Primitive<{ 4 }>

Source§

type Encoder<'a> = [u8; 4]

Source§

impl<T> Encode<T> for Postcard
where T: ?Sized + Serialize,

Source§

type Encoder<'a> = Cow<'a, [u8]> where T: 'a

Source§

impl<T> Encode<T> for Raw
where T: ?Sized + AsRef<[u8]>,

Source§

type Encoder<'a> = Cow<'a, [u8]> where T: 'a