fuel_core_storage::blueprint

Trait BlueprintInspect

Source
pub trait BlueprintInspect<M, S>{
    type KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>;
    type ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>;

    // Provided methods
    fn exists(
        storage: &S,
        key: &M::Key,
        column: S::Column,
    ) -> StorageResult<bool> { ... }
    fn size_of_value(
        storage: &S,
        key: &M::Key,
        column: S::Column,
    ) -> StorageResult<Option<usize>> { ... }
    fn get(
        storage: &S,
        key: &M::Key,
        column: S::Column,
    ) -> StorageResult<Option<M::OwnedValue>> { ... }
}
Expand description

This trait allows defining the agnostic implementation for all storage traits(StorageInspect, StorageMutate, etc) while the main logic is hidden inside the blueprint. It allows quickly adding support for new structures only by implementing the trait and reusing the existing infrastructure in other places. It allows changing the blueprint on the fly in the definition of the table without affecting other areas of the codebase.

The blueprint is responsible for encoding/decoding(usually it is done via KeyCodec and ValueCodec) the key and value and putting/extracting it to/from the storage.

Required Associated Types§

Source

type KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>

The codec used to encode and decode storage key.

Source

type ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>

The codec used to encode and decode storage value.

Provided Methods§

Source

fn exists(storage: &S, key: &M::Key, column: S::Column) -> StorageResult<bool>

Checks if the value exists in the storage.

Source

fn size_of_value( storage: &S, key: &M::Key, column: S::Column, ) -> StorageResult<Option<usize>>

Returns the size of the value in the storage.

Source

fn get( storage: &S, key: &M::Key, column: S::Column, ) -> StorageResult<Option<M::OwnedValue>>

Returns the value from the storage.

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<M, S, KeyCodec, ValueCodec> BlueprintInspect<M, S> for Plain<KeyCodec, ValueCodec>
where M: Mappable, S: KeyValueInspect, KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>, ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>,

Source§

type KeyCodec = KeyCodec

Source§

type ValueCodec = ValueCodec

Source§

impl<M, S, KeyCodec, ValueCodec, Metadata, Nodes, Encoder> BlueprintInspect<M, S> for Merklized<KeyCodec, ValueCodec, Metadata, Nodes, Encoder>
where M: Mappable, S: KeyValueInspect, KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>, ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>,

Source§

type KeyCodec = KeyCodec

Source§

type ValueCodec = ValueCodec

Source§

impl<M, S, KeyCodec, ValueCodec, Metadata, Nodes, KeyConverter> BlueprintInspect<M, S> for Sparse<KeyCodec, ValueCodec, Metadata, Nodes, KeyConverter>
where M: Mappable, S: KeyValueInspect, KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>, ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>,

Source§

type KeyCodec = KeyCodec

Source§

type ValueCodec = ValueCodec