cnidarium

Struct 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>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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