Trait fuel_core_storage::StorageAsRef

source ·
pub trait StorageAsRef {
    // Provided methods
    fn storage<Type>(&self) -> StorageRef<'_, Self, Type>
       where Type: Mappable { ... }
    fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>
       where Type: Mappable { ... }
}
Expand description

Helper trait for StorageInspect to provide user-friendly API to retrieve storage as reference.

§Example

use fuel_storage::{Mappable, StorageInspect, StorageAsRef};

pub struct Contracts;

impl Mappable for Contracts {
    type Key = Self::OwnedKey;
    type OwnedKey = [u8; 32];
    type Value = [u8];
    type OwnedValue = Vec<u8>;
}

pub struct Balances;

impl Mappable for Balances {
    type Key = Self::OwnedKey;
    type OwnedKey = u128;
    type Value = Self::OwnedValue;
    type OwnedValue = u64;
}

pub trait Logic: StorageInspect<Contracts> + StorageInspect<Balances> {
    fn run(&self) {
        // You can specify which storage do you want to call with `storage::<Type>()`
        let _ = self.storage::<Contracts>().get(&[0; 32]);
        let _ = self.storage::<Balances>().get(&123);
    }
}

Provided Methods§

source

fn storage<Type>(&self) -> StorageRef<'_, Self, Type>
where Type: Mappable,

source

fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>
where Type: Mappable,

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> StorageAsRef for T