pub trait StorageAsMut {
    fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>
   where
        Type: Mappable
, { ... } }
Expand description

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

Example

use fuel_storage::{Mappable, StorageMutate, StorageInspect, StorageAsMut};

pub struct Contracts;

impl Mappable for Contracts {
    type Key = [u8; 32];
    type SetValue = [u8];
    type GetValue = Vec<u8>;
}

pub struct Balances;

impl Mappable for Balances {
    type Key = u128;
    type SetValue = u64;
    type GetValue = u64;
}

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

Provided Methods

Implementors