Trait gear_common::storage::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§
Required Methods§
sourcefn mutate<R, F: FnOnce(&mut Option<Self::Value>) -> R>(f: F) -> R
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.
Provided Methods§
sourcefn mutate_exists<R, F: FnOnce(&mut Self::Value) -> R>(f: F) -> Option<R>
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.