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.

Object Safety§

This trait is not object safe.

Implementors§