Trait fuel_storage::StorageAsMut
source · pub trait StorageAsMut {
// Provided methods
fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>
where Type: Mappable { ... }
fn storage_as_mut<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 = 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> + 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§
fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
Object Safety§
This trait is not object safe.