Struct frame_support::pallet_prelude::StorageValue
source · [−]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> StorageEntryMetadataBuilder for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec + StaticTypeInfo,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
impl<Prefix, Value, QueryKind, OnEmpty> StorageEntryMetadataBuilder for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
Prefix: StorageInstance,
Value: FullCodec + StaticTypeInfo,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: Get<QueryKind::Query> + 'static,
Build into entries
the storage metadata entries of a storage given some docs
.
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>ⓘ
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
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
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
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
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
type Query = G::Query
type Query = G::Query
The type that get/take return.
Get the storage key.
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 if closure returns Ok
fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: StorageAppend<Item>,
fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: StorageAppend<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
.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more