pub struct OccupiedEntry<'a, K, V: Serial, S: HasStateApi> { /* private fields */ }
Expand description

A view into an occupied entry in a StateMap. It can be obtained via the StateMap::entry method. This allows looking up or modifying the value at a give key in-place.

The type implements DerefMut which allows the value to be mutated. The Drop implementation ensures that the value is properly stored in the contract state maintained by the node.

This differs from OccupiedEntryRaw in that this automatically handles serialization and provides convenience methods for modifying the value via the DerefMut implementation.

Implementations§

source§

impl<'a, K, V, StateApi> OccupiedEntry<'a, K, V, StateApi>
where K: Serial, V: Serial, StateApi: HasStateApi,

source

pub fn key(&self) -> &K

Get a reference to the key that is associated with this entry.

source

pub fn get_ref(&self) -> &V

Get an immutable reference to the value contained in this entry.

source

pub fn modify<F, A>(&mut self, f: F) -> A
where F: FnOnce(&mut V) -> A,

Modify the value in the entry, and possibly return some information.

source

pub fn try_modify<F, A, E>(&mut self, f: F) -> Result<A, E>
where F: FnOnce(&mut V) -> Result<A, E>,

Like modify, but allows the closure to signal failure, aborting the update.

Trait Implementations§

source§

impl<'a, K, V: Serial, S: HasStateApi> Deref for OccupiedEntry<'a, K, V, S>

§

type Target = V

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, K, V: Serial, S: HasStateApi> DerefMut for OccupiedEntry<'a, K, V, S>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'a, K, V: Serial, S: HasStateApi> Drop for OccupiedEntry<'a, K, V, S>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, K, V, S> RefUnwindSafe for OccupiedEntry<'a, K, V, S>

§

impl<'a, K, V, S> Send for OccupiedEntry<'a, K, V, S>
where K: Send, V: Send, <S as HasStateApi>::EntryType: Send,

§

impl<'a, K, V, S> Sync for OccupiedEntry<'a, K, V, S>
where K: Sync, V: Sync, <S as HasStateApi>::EntryType: Sync,

§

impl<'a, K, V, S> Unpin for OccupiedEntry<'a, K, V, S>
where K: Unpin, V: Unpin, <S as HasStateApi>::EntryType: Unpin,

§

impl<'a, K, V, S> !UnwindSafe for OccupiedEntry<'a, K, V, S>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.