pub trait ValueStorage {
    type Value;

    // Required methods
    fn exists() -> bool;
    fn get() -> Option<Self::Value>;
    fn kill();
    fn mutate<R, F: FnOnce(&mut Option<Self::Value>) -> R>(f: F) -> R;
    fn put(value: Self::Value);
    fn set(value: Self::Value) -> Option<Self::Value>;
    fn take() -> Option<Self::Value>;

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

Represents logic of managing globally stored value for more complicated logic.

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

Required Associated Types§

source

type Value

Stored value type.

Required Methods§

source

fn exists() -> bool

Returns bool, defining does value present.

source

fn get() -> Option<Self::Value>

Gets stored value, if present.

source

fn kill()

Removes stored value.

source

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

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

May return generic type value.

source

fn put(value: Self::Value)

Stores given value.

source

fn set(value: Self::Value) -> Option<Self::Value>

Stores given value and returns previous one, if present.

source

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

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

Provided Methods§

source

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

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

Object Safety§

This trait is not object safe.

Implementors§