Struct sp_runtime::offchain::storage::StorageValueRef
source · pub struct StorageValueRef<'a> { /* private fields */ }
Expand description
An abstraction over local storage value.
Implementations§
source§impl<'a> StorageValueRef<'a>
impl<'a> StorageValueRef<'a>
sourcepub fn persistent(key: &'a [u8]) -> Self
pub fn persistent(key: &'a [u8]) -> Self
Create a new reference to a value in the persistent local storage.
sourcepub fn local(key: &'a [u8]) -> Self
pub fn local(key: &'a [u8]) -> Self
Create a new reference to a value in the fork-aware local storage.
sourcepub fn set(&self, value: &impl Encode)
pub fn set(&self, value: &impl Encode)
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.
sourcepub fn get<T: Decode>(&self) -> Result<Option<T>, StorageRetrievalError>
pub fn get<T: Decode>(&self) -> Result<Option<T>, StorageRetrievalError>
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.
sourcepub 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_val
returns 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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere Self: UniqueSaturatedInto<T>,
T
. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere T: Bounded, S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.