Struct frame_support::storage::types::StorageValue[][src]

pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault>(_);

A type that allow to store a value.

Each value is stored at:

Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX)

Implementations

impl<Prefix, Value, QueryKind, OnEmpty> StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    Prefix: StorageInstance,
    Value: FullCodec,
    QueryKind: QueryKindTrait<Value, OnEmpty>,
    OnEmpty: Get<QueryKind::Query> + 'static, 
[src]

pub fn hashed_key() -> [u8; 32][src]

Get the storage key.

pub fn exists() -> bool[src]

Does the value (explicitly) exist in storage?

pub fn get() -> QueryKind::Query[src]

Load the value from the provided storage instance.

pub fn try_get() -> Result<Value, ()>[src]

Try to get the underlying value from the provided storage instance; Ok if it exists, Err if not.

pub fn translate<O: Decode, F: FnOnce(Option<O>) -> Option<Value>>(
    f: F
) -> Result<Option<Value>, ()>
[src]

Translate a value from some previous type (O) to the current type.

f: F is the translation function.

Returns Err if the storage item could not be interpreted as the old type, and Ok, along with the new value if it could.

NOTE: This operates from and to Option<_> types; no effort is made to respect the default value of the original type.

Warning

This function must be used with care, before being updated the storage still contains the old type, thus other calls (such as get) will fail at decoding it.

Usage

This would typically be called inside the module implementation of on_runtime_upgrade, while ensuring no usage of this storage are made before the call to on_runtime_upgrade. (More precisely prior initialized modules doesn't make use of this storage).

pub fn put<Arg: EncodeLike<Value>>(val: Arg)[src]

Store a value under this key into the provided storage instance.

pub fn set(val: QueryKind::Query)[src]

Store a value under this key into the provided storage instance.

this uses the query type rather than the underlying value.

pub fn mutate<R, F: FnOnce(&mut QueryKind::Query) -> R>(f: F) -> R[src]

Mutate the value

pub fn try_mutate<R, E, F: FnOnce(&mut QueryKind::Query) -> Result<R, E>>(
    f: F
) -> Result<R, E>
[src]

Mutate the value if closure returns Ok

pub fn kill()[src]

Clear the storage value.

pub fn take() -> QueryKind::Query[src]

Take a value from storage, removing it afterwards.

pub fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
    Item: Encode,
    EncodeLikeItem: EncodeLike<Item>,
    Value: StorageAppend<Item>, 
[src]

Append the given item to the value in the storage.

Value is required to implement StorageAppend.

Warning

If the storage item is not encoded properly, the storage item will be overwritten and set to [item]. Any default value set for the storage item will be ignored on overwrite.

pub fn decode_len() -> Option<usize> where
    Value: StorageDecodeLength
[src]

Read the length of the storage value without decoding the entire value.

Value is required to implement StorageDecodeLength.

If the value does not exists or it fails to decode the length, None is returned. Otherwise Some(len) is returned.

Warning

None does not mean that get() does not return a value. The default value is completly ignored by this function.

Trait Implementations

impl<Prefix, Value, QueryKind, OnEmpty> StorageValueMetadata for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    Prefix: StorageInstance,
    Value: FullCodec,
    QueryKind: QueryKindTrait<Value, OnEmpty>,
    OnEmpty: Get<QueryKind::Query> + 'static, 
[src]

Auto Trait Implementations

impl<Prefix, Value, QueryKind, OnEmpty> RefUnwindSafe for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    OnEmpty: RefUnwindSafe,
    Prefix: RefUnwindSafe,
    QueryKind: RefUnwindSafe,
    Value: RefUnwindSafe
[src]

impl<Prefix, Value, QueryKind, OnEmpty> Send for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    OnEmpty: Send,
    Prefix: Send,
    QueryKind: Send,
    Value: Send
[src]

impl<Prefix, Value, QueryKind, OnEmpty> Sync for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    OnEmpty: Sync,
    Prefix: Sync,
    QueryKind: Sync,
    Value: Sync
[src]

impl<Prefix, Value, QueryKind, OnEmpty> Unpin for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    OnEmpty: Unpin,
    Prefix: Unpin,
    QueryKind: Unpin,
    Value: Unpin
[src]

impl<Prefix, Value, QueryKind, OnEmpty> UnwindSafe for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
    OnEmpty: UnwindSafe,
    Prefix: UnwindSafe,
    QueryKind: UnwindSafe,
    Value: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CheckedConversion for T[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IsType<T> for T[src]

impl<T, Outer> IsWrappedBy<Outer> for T where
    T: From<Outer>,
    Outer: AsRef<T> + AsMut<T> + From<T>, 
[src]

pub fn from_ref(outer: &Outer) -> &T[src]

Get a reference to the inner from the outer.

pub fn from_mut(outer: &mut Outer) -> &mut T[src]

Get a mutable reference to the inner from the outer.

impl<T> MaybeRefUnwindSafe for T where
    T: RefUnwindSafe

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SaturatedConversion for T[src]

impl<T, G> StorageValue<T> for G where
    T: FullCodec,
    G: StorageValue<T>, 
[src]

type Query = <G as StorageValue<T>>::Query

The type that get/take return.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T> UncheckedInto<T> for S where
    T: UncheckedFrom<S>, 
[src]

impl<T, S> UniqueSaturatedInto<T> for S where
    T: Bounded,
    S: TryInto<T>, 
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,