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>>
pub fn mutate<T, E, F>( &self, mutate_val: F, ) -> Result<T, MutateStorageError<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> Freeze for StorageValueRef<'a>
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
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 S
impl<T, S> UniqueSaturatedInto<T> for S
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.