[−][src]Trait frame_support::storage::StorageValue
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
type Query
The type that get/take return.
Required methods
fn hashed_key() -> [u8; 32]
Get the storage key.
fn exists() -> bool
Does the value (explicitly) exist in storage?
fn get() -> Self::Query
Load the value from the provided storage instance.
fn try_get() -> Result<T, ()>
Try to get the underlying value from the provided storage instance; Ok
if it exists,
Err
if not.
fn translate<O: Decode, F: FnOnce(Option<O>) -> Option<T>>(
f: F
) -> Result<Option<T>, ()>
f: F
) -> Result<Option<T>, ()>
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_initialize, while
ensuring no usage of this storage are made before the call to on_initialize
. (More
precisely prior initialized modules doesn't make use of this storage).
fn put<Arg: EncodeLike<T>>(val: Arg)
Store a value under this key into the provided storage instance.
fn mutate<R, F: FnOnce(&mut Self::Query) -> R>(f: F) -> R
Mutate the value
fn kill()
Clear the storage value.
fn take() -> Self::Query
Take a value from storage, removing it afterwards.
fn append<Items, Item, EncodeLikeItem>(items: Items) -> Result<(), &'static str> where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem>,
Items::IntoIter: ExactSizeIterator,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem>,
Items::IntoIter: ExactSizeIterator,
Append the given item to the value in the storage.
T
is required to implement codec::EncodeAppend
.
fn append_or_put<Items, Item, EncodeLikeItem>(items: Items) where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem> + Clone + EncodeLike<T>,
Items::IntoIter: ExactSizeIterator,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem> + Clone + EncodeLike<T>,
Items::IntoIter: ExactSizeIterator,
Append the given items to the value in the storage.
T
is required to implement Codec::EncodeAppend
.
Upon any failure, it replaces items
as the new value (assuming that the previous stored
data is simply corrupt and no longer usable).
WARNING
use with care; if your use-case is not exactly as what this function is doing, you should use append and sensibly handle failure within the runtime code if it happens.
fn decode_len() -> Result<usize, &'static str> where
T: DecodeLength + Len,
T: DecodeLength + Len,
Read the length of the value in a fast way, without decoding the entire value.
T
is required to implement Codec::DecodeLength
.
Implementors
impl<T: FullCodec, G: StorageValue<T>> StorageValue<T> for G
[src]
type Query = G::Query
fn hashed_key() -> [u8; 32]
[src]
fn exists() -> bool
[src]
fn get() -> Self::Query
[src]
fn try_get() -> Result<T, ()>
[src]
fn translate<O: Decode, F: FnOnce(Option<O>) -> Option<T>>(
f: F
) -> Result<Option<T>, ()>
[src]
f: F
) -> Result<Option<T>, ()>
fn put<Arg: EncodeLike<T>>(val: Arg)
[src]
fn kill()
[src]
fn mutate<R, F: FnOnce(&mut G::Query) -> R>(f: F) -> R
[src]
fn take() -> G::Query
[src]
fn append<Items, Item, EncodeLikeItem>(items: Items) -> Result<(), &'static str> where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem>,
Items::IntoIter: ExactSizeIterator,
[src]
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem>,
Items::IntoIter: ExactSizeIterator,
Append the given items to the value in the storage.
T
is required to implement codec::EncodeAppend
.
fn append_or_put<Items, Item, EncodeLikeItem>(items: Items) where
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem> + Clone + EncodeLike<T>,
Items::IntoIter: ExactSizeIterator,
[src]
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
T: EncodeAppend<Item = Item>,
Items: IntoIterator<Item = EncodeLikeItem> + Clone + EncodeLike<T>,
Items::IntoIter: ExactSizeIterator,
Safely append the given items to the value in the storage. If a codec error occurs, then the
old (presumably corrupt) value is replaced with the given items
.
T
is required to implement codec::EncodeAppend
.
fn decode_len() -> Result<usize, &'static str> where
T: DecodeLength,
T: Len,
[src]
T: DecodeLength,
T: Len,
Read the length of the value in a fast way, without decoding the entire value.
T
is required to implement Codec::DecodeLength
.
Note that 0
is returned as the default value if no encoded value exists at the given key.
Therefore, this function cannot be used as a sign of existence. use the ::exists()
function for this purpose.