Skip to main content

run

Function run 

Source
pub fn run<M, S, State>(
    machine: &mut M,
    initialize: impl FnOnce(&mut M) -> Result<State>,
    step: impl FnMut(&mut M, &mut State) -> Result<ControlFlow<()>>,
) -> Result<()>
where M: HasProgram<Program = ExecutionState<S>>,
Expand description

Drive an invocation with caller-defined initialization and iteration policy.

After rejecting reentrant execution, calls initialize once, including for halted or suspended invocations. The returned state is passed to step on each iteration while the program is RunState::Runnable. Returning ControlFlow::Break ends this call without changing the program’s run state. Use execute_instruction inside step for checked fetch/dispatch.

Call ExecutionState::start before running a new invocation. Initialization can inspect a suspended invocation and call ExecutionState::resume_at to continue it. The execution guard is released on both success and returned errors; unwinding through a panic does not release it. Device mutations are retained, so the caller chooses whether an error can be retried.

§Errors

Rejects reentrant execution and propagates initialization or step errors.