Struct cnidarium::StateDelta

source ·
pub struct StateDelta<S: StateRead> { /* private fields */ }
Expand description

An arbitrarily-deeply nested stack of delta updates to an underlying state.

This API allows exploring a tree of possible execution paths concurrently, before finally selecting one and applying it to the underlying state.

Using this API requires understanding its invariants.

On creation, StateDelta::new takes ownership of a StateRead + StateWrite instance, acquiring a “write lock” over the underlying state (since &mut S is StateWrite if S: StateWrite, it’s possible to pass a unique reference).

The resulting StateDelta instance is a “leaf” state, and can be used for reads and writes, following the some execution path.

When two potential execution paths diverge, delta.fork() can be used to fork the state update. The new forked StateDelta will include all previous state writes made to the original (and its ancestors). Any writes made to the original StateDelta after fork() is called will not be seen by the forked state.

Finally, after some execution path has been selected, calling delta.apply() on one of the possible state updates will commit the changes to the underlying state instance, and invalidate all other delta updates in the same family. It is a programming error to use the other delta updates after apply() has been called, but ideally this should not be a problem in practice: the API is intended to explore a tree of possible execution paths; once one has been selected, the others should be discarded.

Implementations§

source§

impl<S: StateRead> StateDelta<S>

source

pub fn new(state: S) -> Self

Create a new tree of possible updates to an underlying state.

source

pub fn fork(&mut self) -> Self

Fork execution, returning a new child state that includes all previous changes.

source

pub fn flatten(self) -> (S, Cache)

Flatten all changes in this branch of the tree into a single Cache, invalidating all other branches of the tree and releasing the underlying state back to the caller.

The apply method is a convenience wrapper around this that applies the changes to the underlying state.

source§

impl<S: StateRead + StateWrite> StateDelta<S>

source

pub fn apply(self) -> (S, Vec<Event>)

Apply all changes in this branch of the tree to the underlying state, releasing it back to the caller and invalidating all other branches of the tree.

source§

impl<S: StateRead + StateWrite> StateDelta<Arc<S>>

source

pub fn try_apply(self) -> Result<(S, Vec<Event>)>

Trait Implementations§

source§

impl<S: Debug + StateRead> Debug for StateDelta<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S: StateRead> StateRead for StateDelta<S>

§

type GetRawFut = CacheFuture<<S as StateRead>::GetRawFut>

§

type PrefixRawStream = StateDeltaPrefixRawStream<<S as StateRead>::PrefixRawStream>

§

type PrefixKeysStream = StateDeltaPrefixKeysStream<<S as StateRead>::PrefixKeysStream>

§

type NonconsensusPrefixRawStream = StateDeltaNonconsensusPrefixRawStream<<S as StateRead>::NonconsensusPrefixRawStream>

§

type NonconsensusRangeRawStream = StateDeltaNonconsensusRangeRawStream<<S as StateRead>::NonconsensusRangeRawStream>

source§

fn get_raw(&self, key: &str) -> Self::GetRawFut

Gets a value from the verifiable key-value store as raw bytes. Read more
source§

fn nonverifiable_get_raw(&self, key: &[u8]) -> Self::GetRawFut

Gets a byte value from the non-verifiable key-value store. Read more
source§

fn object_type(&self, key: &'static str) -> Option<TypeId>

Gets the [TypeId] of the object stored at key in the ephemeral key-object store, if any is present.
source§

fn object_get<T: Any + Send + Sync + Clone>( &self, key: &'static str ) -> Option<T>

Gets an object from the ephemeral key-object store. Read more
source§

fn prefix_raw(&self, prefix: &str) -> Self::PrefixRawStream

Retrieve all values for keys matching a prefix from the verifiable key-value store, as raw bytes. Read more
source§

fn prefix_keys(&self, prefix: &str) -> Self::PrefixKeysStream

Retrieve all keys (but not values) matching a prefix from the verifiable key-value store.
source§

fn nonverifiable_prefix_raw( &self, prefix: &[u8] ) -> Self::NonconsensusPrefixRawStream

Retrieve all values for keys matching a prefix from the non-verifiable key-value store, as raw bytes. Read more
source§

fn nonverifiable_range_raw( &self, prefix: Option<&[u8]>, range: impl RangeBounds<Vec<u8>> ) -> Result<Self::NonconsensusRangeRawStream>

Retrieve all values for keys in a range from the non-verifiable key-value store, as raw bytes. This method does not support inclusive ranges, and will return an error if passed one. Read more
source§

impl<S: StateRead> StateWrite for StateDelta<S>

source§

fn put_raw(&mut self, key: String, value: OwnedValue)

Puts raw bytes into the verifiable key-value store with the given key.
source§

fn delete(&mut self, key: String)

Delete a key from the verifiable key-value store.
source§

fn nonverifiable_delete(&mut self, key: Vec<u8>)

Delete a key from non-verifiable key-value storage.
source§

fn nonverifiable_put_raw(&mut self, key: Vec<u8>, value: Vec<u8>)

Puts raw bytes into the non-verifiable key-value store with the given key.
source§

fn object_put<T: Clone + Any + Send + Sync>( &mut self, key: &'static str, value: T )

Puts an object into the ephemeral object store with the given key. Read more
source§

fn object_delete(&mut self, key: &'static str)

Deletes a key from the ephemeral object store.
source§

fn object_merge( &mut self, objects: BTreeMap<&'static str, Option<Box<dyn Any + Send + Sync>>> )

Merge a set of object changes into this StateWrite. Read more
source§

fn record(&mut self, event: Event)

Record that an ABCI event occurred while building up this set of state changes.

Auto Trait Implementations§

§

impl<S> Freeze for StateDelta<S>

§

impl<S> !RefUnwindSafe for StateDelta<S>

§

impl<S> Send for StateDelta<S>

§

impl<S> Sync for StateDelta<S>

§

impl<S> Unpin for StateDelta<S>

§

impl<S> !UnwindSafe for StateDelta<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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more