ValueStorage

Trait ValueStorage 

Source
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.

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<TIStorage, TIProvider> ValueStorage for TotalIssuanceWrap<TIStorage, TIProvider>
where TIStorage: TotalIssuanceStorage<TIProvider> + 'static, TIProvider: TotalIssuanceProvider + 'static,

Available on crate feature std only.