Struct sov_state::StateValue
source · pub struct StateValue<V, Codec = BorshCodec> { /* private fields */ }Expand description
Container for a single value.
Implementations§
source§impl<V> StateValue<V>
impl<V> StateValue<V>
sourcepub fn new(prefix: Prefix) -> Self
pub fn new(prefix: Prefix) -> Self
Crates a new StateValue with the given prefix and the default
StateValueCodec (i.e. BorshCodec).
source§impl<V, Codec> StateValue<V, Codec>
impl<V, Codec> StateValue<V, Codec>
sourcepub fn with_codec(prefix: Prefix, codec: Codec) -> Self
pub fn with_codec(prefix: Prefix, codec: Codec) -> Self
Creates a new StateValue with the given prefix and codec.
sourcepub fn prefix(&self) -> &Prefix
pub fn prefix(&self) -> &Prefix
Returns the prefix used when this StateValue was created.
source§impl<V, Codec> StateValue<V, Codec>where
Codec: StateCodec,
Codec::ValueCodec: StateValueCodec<V>,
impl<V, Codec> StateValue<V, Codec>where Codec: StateCodec, Codec::ValueCodec: StateValueCodec<V>,
sourcepub fn set<S: Storage>(&self, value: &V, working_set: &mut WorkingSet<S>)
pub fn set<S: Storage>(&self, value: &V, working_set: &mut WorkingSet<S>)
Sets a value in the StateValue.
sourcepub fn get<S: Storage>(&self, working_set: &mut WorkingSet<S>) -> Option<V>
pub fn get<S: Storage>(&self, working_set: &mut WorkingSet<S>) -> Option<V>
Gets a value from the StateValue or None if the value is absent.
sourcepub fn get_or_err<S: Storage>(
&self,
working_set: &mut WorkingSet<S>
) -> Result<V, Error>
pub fn get_or_err<S: Storage>( &self, working_set: &mut WorkingSet<S> ) -> Result<V, Error>
Gets a value from the StateValue or Error if the value is absent.
sourcepub fn remove<S: Storage>(&self, working_set: &mut WorkingSet<S>) -> Option<V>
pub fn remove<S: Storage>(&self, working_set: &mut WorkingSet<S>) -> Option<V>
Removes a value from the StateValue, returning the value (or None if the key is absent).
sourcepub fn remove_or_err<S: Storage>(
&self,
working_set: &mut WorkingSet<S>
) -> Result<V, Error>
pub fn remove_or_err<S: Storage>( &self, working_set: &mut WorkingSet<S> ) -> Result<V, Error>
Removes a value and from the StateValue, returning the value (or Error if the key is absent).
sourcepub fn delete<S: Storage>(&self, working_set: &mut WorkingSet<S>)
pub fn delete<S: Storage>(&self, working_set: &mut WorkingSet<S>)
Deletes a value from the StateValue.
Trait Implementations§
source§impl<V, Codec> BorshDeserialize for StateValue<V, Codec>where
PhantomData<V>: BorshDeserialize,
Codec: BorshDeserialize,
Prefix: BorshDeserialize,
impl<V, Codec> BorshDeserialize for StateValue<V, Codec>where PhantomData<V>: BorshDeserialize, Codec: BorshDeserialize, Prefix: BorshDeserialize,
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where R: Read,
source§impl<V, Codec> BorshSerialize for StateValue<V, Codec>where
PhantomData<V>: BorshSerialize,
Codec: BorshSerialize,
Prefix: BorshSerialize,
impl<V, Codec> BorshSerialize for StateValue<V, Codec>where PhantomData<V>: BorshSerialize, Codec: BorshSerialize, Prefix: BorshSerialize,
source§impl<V: Clone, Codec: Clone> Clone for StateValue<V, Codec>
impl<V: Clone, Codec: Clone> Clone for StateValue<V, Codec>
source§fn clone(&self) -> StateValue<V, Codec>
fn clone(&self) -> StateValue<V, Codec>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<'de, V, Codec> Deserialize<'de> for StateValue<V, Codec>where
Codec: Deserialize<'de>,
impl<'de, V, Codec> Deserialize<'de> for StateValue<V, Codec>where Codec: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<V: PartialEq, Codec: PartialEq> PartialEq<StateValue<V, Codec>> for StateValue<V, Codec>
impl<V: PartialEq, Codec: PartialEq> PartialEq<StateValue<V, Codec>> for StateValue<V, Codec>
source§fn eq(&self, other: &StateValue<V, Codec>) -> bool
fn eq(&self, other: &StateValue<V, Codec>) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl<V, Codec> Serialize for StateValue<V, Codec>where
Codec: Serialize,
impl<V, Codec> Serialize for StateValue<V, Codec>where Codec: Serialize,
impl<V, Codec> StructuralPartialEq for StateValue<V, Codec>
Auto Trait Implementations§
impl<V, Codec> RefUnwindSafe for StateValue<V, Codec>where Codec: RefUnwindSafe, V: RefUnwindSafe,
impl<V, Codec> Send for StateValue<V, Codec>where Codec: Send, V: Send,
impl<V, Codec> Sync for StateValue<V, Codec>where Codec: Sync, V: Sync,
impl<V, Codec> Unpin for StateValue<V, Codec>where Codec: Unpin, V: Unpin,
impl<V, Codec> UnwindSafe for StateValue<V, Codec>where Codec: UnwindSafe, V: UnwindSafe,
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
Mutably borrows from an owned value. Read more