Trait fuel_core_storage::codec::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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Encode<Block<Bytes32>> for BlockEncoder

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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