ink_storage_traits

Trait Storable

Source
pub trait Storable: Sized {
    // Required methods
    fn encode<T: Output + ?Sized>(&self, dest: &mut T);
    fn decode<I: Input>(input: &mut I) -> Result<Self, Error>;
    fn encoded_size(&self) -> usize;
}
Expand description

Trait for representing types which can be read and written to storage.

This trait is not the same as the scale::Codec. Each type that implements scale::Codec are storable by default and transferable between contracts. But not each storable type is transferable.

Required Methods§

Source

fn encode<T: Output + ?Sized>(&self, dest: &mut T)

Convert self to a slice and append it to the destination.

Source

fn decode<I: Input>(input: &mut I) -> Result<Self, Error>

Attempt to deserialize the value from input.

Source

fn encoded_size(&self) -> usize

The exact number of bytes this type consumes in the encoded form.

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<P> Storable for P
where P: Codec,

Types which implement scale::Encode and scale::Decode are Storable by default because they can be written directly into the storage cell.