fuel_core_storage

Trait 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§

Source

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

Source

fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>
where Type: Mappable,

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<T> StorageAsMut for T