Skip to main content

MapStorage

Trait MapStorage 

Source
pub trait MapStorage {
    type Key;
    type Value;

    // Required methods
    fn contains_key(key: &Self::Key) -> bool;
    fn get(key: &Self::Key) -> Option<Self::Value>;
    fn insert(key: Self::Key, value: Self::Value);
    fn mutate<R, F: FnOnce(&mut Option<Self::Value>) -> R>(
        key: Self::Key,
        f: F,
    ) -> R;
    fn mutate_values<F: FnMut(Self::Value) -> Self::Value>(f: F);
    fn remove(key: Self::Key);
    fn clear();
    fn take(key: Self::Key) -> Option<Self::Value>;

    // Provided method
    fn mutate_exists<R, F: FnOnce(&mut Self::Value) -> R>(
        key: Self::Key,
        f: F,
    ) -> Option<R> { ... }
}
Expand description

Represents logic of managing globally stored single-key map for more complicated logic.

In fact, represents custom implementation/wrapper around of Substrate’s StorageMap with OptionQuery.

Required Associated Types§

Source

type Key

Map’s key type.

Source

type Value

Map’s stored value type.

Required Methods§

Source

fn contains_key(key: &Self::Key) -> bool

Returns bool, defining does map contain value under given key.

Source

fn get(key: &Self::Key) -> Option<Self::Value>

Gets value stored under given key, if present.

Source

fn insert(key: Self::Key, value: Self::Value)

Inserts value with given key.

Source

fn mutate<R, F: FnOnce(&mut Option<Self::Value>) -> R>( key: Self::Key, f: F, ) -> R

Mutates value by Option reference, which stored (or not in None case) under given key with given function.

May return generic type value.

Source

fn mutate_values<F: FnMut(Self::Value) -> Self::Value>(f: F)

Mutates all stored values with given convert function.

Source

fn remove(key: Self::Key)

Removes value stored under the given key.

Source

fn clear()

Removes all values.

Source

fn take(key: Self::Key) -> Option<Self::Value>

Gets value stored under given key, if present, and removes it from storage.

Provided Methods§

Source

fn mutate_exists<R, F: FnOnce(&mut Self::Value) -> R>( key: Self::Key, f: F, ) -> Option<R>

Works the same as Self::mutate, but triggers if value present.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<GNStorage, GNProvider> MapStorage for GasNodesWrap<GNStorage, GNProvider>
where GNStorage: GasNodesStorage<GNProvider> + 'static, GNProvider: GasNodesProvider + 'static,

Available on crate feature std only.
Source§

impl<T: AuxiliaryStorageWrap> MapStorage for T

Available on crate feature std only.