Struct oasis_runtime_sdk::state::CurrentState
source · pub struct CurrentState;
Expand description
State attached to the current thread.
Implementations§
source§impl CurrentState
impl CurrentState
sourcepub fn enter<S, F, R>(root: S, f: F) -> R
pub fn enter<S, F, R>(root: S, f: F) -> R
Attach a new state to the current thread and enter the state’s context.
The passed store is used as the root store.
§Panics
This method will panic if called from within a CurrentState::with
block.
sourcepub fn enter_opts<S, F, R>(opts: Options, root: S, f: F) -> R
pub fn enter_opts<S, F, R>(opts: Options, root: S, f: F) -> R
Attach a new state to the current thread and enter the state’s context.
The passed store is used as the root store.
§Panics
This method will panic if called from within a CurrentState::with
block or if the mode
has not been explicitly set in opts
.
sourcepub fn with<F, R>(f: F) -> R
pub fn with<F, R>(f: F) -> R
Run a closure with the currently active state.
§Panics
This method will panic if called outside CurrentState::enter
or if any transaction methods
are called from the closure.
sourcepub fn with_store<F, R>(f: F) -> R
pub fn with_store<F, R>(f: F) -> R
Run a closure with the store of the currently active state.
§Panics
This method will panic if called outside CurrentState::enter
or if any transaction methods
are called from the closure.
sourcepub fn with_env<F, R>(f: F) -> Rwhere
F: FnOnce(&Environment) -> R,
pub fn with_env<F, R>(f: F) -> Rwhere
F: FnOnce(&Environment) -> R,
Run a closure with the environment of the currently active state.
§Panics
This method will panic if called outside CurrentState::enter
or if any transaction methods
are called from the closure.
sourcepub fn with_env_origin<F, R>(f: F) -> Rwhere
F: FnOnce(&Environment) -> R,
pub fn with_env_origin<F, R>(f: F) -> Rwhere
F: FnOnce(&Environment) -> R,
Run a closure with the origin environment of the currently active state.
§Panics
This method will panic if called outside CurrentState::enter
or if any transaction methods
are called from the closure.
sourcepub fn start_transaction()
pub fn start_transaction()
Start a new transaction by opening a new child state.
§Panics
This method will panic if called outside CurrentState::enter
or if called within a
CurrentState::with
block.
sourcepub fn commit_transaction()
pub fn commit_transaction()
Commit a previously started transaction.
§Panics
This method will panic if called outside CurrentState::enter
, if there is no currently
open transaction (started via CurrentState::start_transaction
) or if called within a
CurrentState::with
block.
sourcepub fn rollback_transaction()
pub fn rollback_transaction()
Rollback a previously started transaction.
§Panics
This method will panic if called outside CurrentState::enter
, if there is no currently
open transaction (started via CurrentState::start_transaction
) or if called within a
CurrentState::with
block.
sourcepub fn with_transaction<F, R, Rs>(f: F) -> R
pub fn with_transaction<F, R, Rs>(f: F) -> R
Run a closure within a state transaction.
If the closure returns TransactionResult::Commit(R)
then the child state is committed,
otherwise the child state is rolled back.
sourcepub fn with_transaction_opts<F, R, Rs>(opts: Options, f: F) -> R
pub fn with_transaction_opts<F, R, Rs>(opts: Options, f: F) -> R
Run a closure within a state transaction, allowing the caller to customize state.
If the closure returns TransactionResult::Commit(R)
then the child state is committed,
otherwise the child state is rolled back.