Struct frame_support::pallet_prelude::StorageValue [−][src]
pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault>(_);
Expand description
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,
impl<Prefix, Value, QueryKind, OnEmpty> StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
Get the storage key.
Try to get the underlying value from the provided storage instance; Ok
if it exists,
Err
if not.
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).
Store a value under this key into the provided storage instance.
Store a value under this key into the provided storage instance.
this uses the query type rather than the underlying value.
Mutate the value if closure returns Ok
pub fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Value: StorageAppend<Item>,
pub fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Value: StorageAppend<Item>,
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.
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.
pub fn try_append<Item, EncodeLikeItem>(item: EncodeLikeItem) -> Result<(), ()> where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Value: StorageTryAppend<Item>,
pub fn try_append<Item, EncodeLikeItem>(item: EncodeLikeItem) -> Result<(), ()> where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Value: StorageTryAppend<Item>,
Try and append the given item to the value in the storage.
Is only available if Value
of the storage implements StorageTryAppend
.
Trait Implementations
impl<Prefix, Value, QueryKind, OnEmpty> PartialStorageInfoTrait for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
impl<Prefix, Value, QueryKind, OnEmpty> PartialStorageInfoTrait for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
It doesn’t require to implement MaxEncodedLen
and give no information for max_size
.
fn partial_storage_info() -> Vec<StorageInfo>ⓘ
impl<Prefix, Value, QueryKind, OnEmpty> StorageInfoTrait for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec + MaxEncodedLen,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
impl<Prefix, Value, QueryKind, OnEmpty> StorageInfoTrait for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec + MaxEncodedLen,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
fn storage_info() -> Vec<StorageInfo>ⓘ
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,
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,
Auto Trait Implementations
impl<Prefix, Value, QueryKind, OnEmpty> RefUnwindSafe for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
OnEmpty: RefUnwindSafe,
Prefix: RefUnwindSafe,
QueryKind: RefUnwindSafe,
Value: RefUnwindSafe,
impl<Prefix, Value, QueryKind, OnEmpty> Send for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
OnEmpty: Send,
Prefix: Send,
QueryKind: Send,
Value: Send,
impl<Prefix, Value, QueryKind, OnEmpty> Sync for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
OnEmpty: Sync,
Prefix: Sync,
QueryKind: Sync,
Value: Sync,
impl<Prefix, Value, QueryKind, OnEmpty> Unpin for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
OnEmpty: Unpin,
Prefix: Unpin,
QueryKind: Unpin,
Value: Unpin,
impl<Prefix, Value, QueryKind, OnEmpty> UnwindSafe for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
OnEmpty: UnwindSafe,
Prefix: UnwindSafe,
QueryKind: UnwindSafe,
Value: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
type Query = <G as StorageValue<T>>::Query
type Query = <G as StorageValue<T>>::Query
The type that get/take return.
Get the storage key.
Load the value from the provided storage instance.
Try to get the underlying value from the provided storage instance. Read more
Translate a value from some previous type (O
) to the current type. Read more
Store a value under this key into the provided storage instance.
Store a value under this key into the provided storage instance; this uses the query type rather than the underlying value. Read more
Mutate the value
pub fn try_mutate<R, E, F>(F) -> Result<R, E> where
F: FnOnce(&mut <G as StorageValue<T>>::Query) -> Result<R, E>,
pub fn try_mutate<R, E, F>(F) -> Result<R, E> where
F: FnOnce(&mut <G as StorageValue<T>>::Query) -> Result<R, E>,
Mutate the value if closure returns Ok
Take a value from storage, removing it afterwards.
pub fn append<Item, EncodeLikeItem>(EncodeLikeItem) where
T: StorageAppend<Item>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
pub fn append<Item, EncodeLikeItem>(EncodeLikeItem) where
T: StorageAppend<Item>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Append the given item to the value in the storage. Read more
Read the length of the storage value without decoding the entire value. Read more
impl<T, I, StorageValueT> TryAppendValue<T, I> for StorageValueT where
I: Encode,
T: FullCodec + StorageTryAppend<I>,
StorageValueT: StorageValue<T>,
impl<T, I, StorageValueT> TryAppendValue<T, I> for StorageValueT where
I: Encode,
T: FullCodec + StorageTryAppend<I>,
StorageValueT: StorageValue<T>,
Try and append the item
into the storage item. Read more
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
pub fn vzip(self) -> V