pub trait BlueprintInspect<M, S>where
M: Mappable,
S: KeyValueInspect,{
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§
sourcetype KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>
type KeyCodec: Encode<M::Key> + Decode<M::OwnedKey>
The codec used to encode and decode storage key.
sourcetype ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>
type ValueCodec: Encode<M::Value> + Decode<M::OwnedValue>
The codec used to encode and decode storage value.
Provided Methods§
sourcefn exists(storage: &S, key: &M::Key, column: S::Column) -> StorageResult<bool>
fn exists(storage: &S, key: &M::Key, column: S::Column) -> StorageResult<bool>
Checks if the value exists in the storage.
sourcefn size_of_value(
storage: &S,
key: &M::Key,
column: S::Column,
) -> StorageResult<Option<usize>>
fn size_of_value( storage: &S, key: &M::Key, column: S::Column, ) -> StorageResult<Option<usize>>
Returns the size of the value in the storage.
sourcefn get(
storage: &S,
key: &M::Key,
column: S::Column,
) -> StorageResult<Option<M::OwnedValue>>
fn get( storage: &S, key: &M::Key, column: S::Column, ) -> StorageResult<Option<M::OwnedValue>>
Returns the value from the storage.