Trait subsocial_runtime::StorageValue [−][src]
A trait for working with macro-generated storage values under the substrate storage API.
Details on implementation can be found at
[generator::StorageValue
]
Associated Types
Loading content...Required methods
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() -> Self::Query
[src]
Load the value from the provided storage instance.
pub fn try_get() -> Result<T, ()>
[src]
Try to get the underlying value from the provided storage instance; Ok
if it exists,
Err
if not.
pub fn translate<O, F>(f: F) -> Result<Option<T>, ()> where
F: FnOnce(Option<O>) -> Option<T>,
O: Decode,
[src]
F: FnOnce(Option<O>) -> Option<T>,
O: Decode,
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>(val: Arg) where
Arg: EncodeLike<T>,
[src]
Arg: EncodeLike<T>,
Store a value under this key into the provided storage instance.
pub fn set(val: Self::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>(f: F) -> R where
F: FnOnce(&mut Self::Query) -> R,
[src]
F: FnOnce(&mut Self::Query) -> R,
Mutate the value
pub fn try_mutate<R, E, F>(f: F) -> Result<R, E> where
F: FnOnce(&mut Self::Query) -> Result<R, E>,
[src]
F: FnOnce(&mut Self::Query) -> Result<R, E>,
Mutate the value if closure returns Ok
pub fn kill()
[src]
Clear the storage value.
pub fn take() -> Self::Query
[src]
Take a value from storage, removing it afterwards.
pub fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
Item: Encode,
T: StorageAppend<Item>,
EncodeLikeItem: EncodeLike<Item>,
[src]
Item: Encode,
T: StorageAppend<Item>,
EncodeLikeItem: EncodeLike<Item>,
Append the given item to the value in the storage.
T
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.
Provided methods
pub fn decode_len() -> Option<usize> where
T: StorageDecodeLength,
[src]
T: StorageDecodeLength,
Read the length of the storage value without decoding the entire value.
T
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.
Implementors
impl<T, G> StorageValue<T> for G where
T: FullCodec,
G: StorageValue<T>,
[src]
T: FullCodec,
G: StorageValue<T>,
type Query = <G as StorageValue<T>>::Query
pub fn hashed_key() -> [u8; 32]
[src]
pub fn exists() -> bool
[src]
pub fn get() -> <G as StorageValue<T>>::Query
[src]
pub fn try_get() -> Result<T, ()>
[src]
pub fn translate<O, F>(f: F) -> Result<Option<T>, ()> where
F: FnOnce(Option<O>) -> Option<T>,
O: Decode,
[src]
F: FnOnce(Option<O>) -> Option<T>,
O: Decode,
pub fn put<Arg>(val: Arg) where
Arg: EncodeLike<T>,
[src]
Arg: EncodeLike<T>,
pub fn set(maybe_val: <G as StorageValue<T>>::Query)
[src]
pub fn kill()
[src]
pub fn mutate<R, F>(f: F) -> R where
F: FnOnce(&mut <G as StorageValue<T>>::Query) -> R,
[src]
F: FnOnce(&mut <G as StorageValue<T>>::Query) -> R,
pub fn try_mutate<R, E, F>(f: F) -> Result<R, E> where
F: FnOnce(&mut <G as StorageValue<T>>::Query) -> Result<R, E>,
[src]
F: FnOnce(&mut <G as StorageValue<T>>::Query) -> Result<R, E>,
pub fn take() -> <G as StorageValue<T>>::Query
[src]
pub fn append<Item, EncodeLikeItem>(item: EncodeLikeItem) where
Item: Encode,
T: StorageAppend<Item>,
EncodeLikeItem: EncodeLike<Item>,
[src]
Item: Encode,
T: StorageAppend<Item>,
EncodeLikeItem: EncodeLike<Item>,