Struct sp_runtime::offchain::storage::StorageValueRef
source · [−]pub struct StorageValueRef<'a> { /* private fields */ }Expand description
An abstraction over local storage value.
Implementations
Create a new reference to a value in the persistent local storage.
Create a new reference to a value in the fork-aware local storage.
Set the value of the storage to encoding of given parameter.
Note that the storage may be accessed by workers running concurrently,
if you happen to write a get-check-set pattern you should most likely
be using mutate instead.
Retrieve & decode the value from storage.
Note that if you want to do some checks based on the value
and write changes after that, you should rather be using mutate.
Returns the value if stored. Returns an error if the value could not be decoded.
pub fn mutate<T, E, F>(
&self,
mutate_val: F
) -> Result<T, MutateStorageError<T, E>> where
T: Codec,
F: FnOnce(Result<Option<T>, StorageRetrievalError>) -> Result<T, E>,
pub fn mutate<T, E, F>(
&self,
mutate_val: F
) -> Result<T, MutateStorageError<T, E>> where
T: Codec,
F: FnOnce(Result<Option<T>, StorageRetrievalError>) -> Result<T, E>,
Retrieve & decode the current value and set it to a new value atomically.
Function mutate_val takes as input the current value and should
return a new value that is attempted to be written to storage.
This function returns:
Ok(T)in case the value has been successfully set.Err(MutateStorageError::ConcurrentModification(T))in case the value was calculated by the passed closuremutate_val, but it could not be stored.Err(MutateStorageError::ValueFunctionFailed(_))in casemutate_valreturns an error.
Auto Trait Implementations
impl<'a> RefUnwindSafe for StorageValueRef<'a>
impl<'a> Send for StorageValueRef<'a>
impl<'a> Sync for StorageValueRef<'a>
impl<'a> Unpin for StorageValueRef<'a>
impl<'a> UnwindSafe for StorageValueRef<'a>
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
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