pub struct State { /* private fields */ }
Expand description

Mutable block state of a runtime.

The state includes storage, emitted events, messages to consensus layer, etc. States can be nested via open, commit and rollback methods which behave like transactions.

Implementations§

source§

impl State

source

pub fn open(&mut self)

Open a child state after which self will point to the child state.

source

pub fn commit(&mut self)

Commit the current state and return to its parent state.

§Panics

This method will panic when attempting to commit the root state.

source

pub fn rollback(&mut self)

Rollback the current state and return to its parent state.

§Panics

This method will panic when attempting to rollback the root state.

source

pub fn block_value<V: Any>(&mut self, key: &'static str) -> StateValue<'_, V>

Fetches a block state value entry.

Block values live as long as the root State and are propagated to child states. They are not affected by state rollbacks. If you need state-scoped values, use local values.

source

pub fn local_value<V: Any>(&mut self, key: &'static str) -> StateValue<'_, V>

Fetches a local state value entry.

Local values only live as long as the current State, are dropped upon exiting to parent state and child states start with an empty set. If you need longer-lived values, use block values.

source

pub fn hide_block_values(&mut self)

Hides block values from the current state which will have an empty set of values after this method returns. Hidden values will be restored upon exit to parent state.

source

pub fn emitted_messages_count(&self) -> usize

Emitted messages count returns the number of messages emitted so far across this and all parent states.

source

pub fn emitted_messages_local_count(&self) -> usize

Emitted messages count returns the number of messages emitted so far in this state, not counting any parent states.

source

pub fn emitted_messages_max<C: Context>(&self, ctx: &C) -> u32

Maximum number of messages that can be emitted.

source

pub fn emit_message<C: Context>( &mut self, ctx: &C, msg: Message, hook: MessageEventHookInvocation ) -> Result<(), Error>

Queue a message to be emitted by the runtime for consensus layer to process.

source

pub fn take_messages(&mut self) -> Vec<(Message, MessageEventHookInvocation)>

Take all messages accumulated in the current state.

source

pub fn emit_event<E: Event>(&mut self, event: E)

Emit an event.

source

pub fn emit_event_raw(&mut self, etag: EventTag)

Emit a raw event.

source

pub fn emit_unconditional_event<E: Event>(&mut self, event: E)

Emit an unconditional event.

The only difference to regular events is that these are handled as a separate set.

source

pub fn take_events(&mut self) -> EventTags

Take all regular events accumulated in the current state.

source

pub fn take_unconditional_events(&mut self) -> EventTags

Take all unconditional events accumulated in the current state.

source

pub fn take_all_events(&mut self) -> EventTags

Take all events accumulated in the current state and return the merged set.

source

pub fn store(&mut self) -> &mut dyn Store

Store associated with the state.

§Panics

This method will panic if no store exists.

source

pub fn has_pending_store_updates(&self) -> bool

Whether the store associated with the state has any pending updates.

source

pub fn pending_store_update_byte_size(&self) -> usize

Size (in bytes) of any pending updates in the associated store.

source

pub fn rng(&mut self) -> &mut RootRng

Random number generator.

source

pub fn env(&self) -> &Environment

Environment information.

source

pub fn level(&self) -> usize

Returns the nesting level of the current state.

Auto Trait Implementations§

§

impl !RefUnwindSafe for State

§

impl !Send for State

§

impl !Sync for State

§

impl Unpin for State

§

impl !UnwindSafe for State

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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