Skip to main content

StepResult

Enum StepResult 

Source
pub enum StepResult {
    Continue,
    Complete(RuntimeValue),
    NeedImports(Vec<ImportRequest>),
    Suspended {
        pending: Vec<Order>,
        cancelled: Vec<OrderId>,
    },
    Done,
}
Expand description

Result of executing a single step.

Step-based execution gives the host full control over when execution should stop. The host calls step() repeatedly until it receives a terminal result (Complete, NeedImports, Suspended), or decides to stop early.

§Execution Loop

use tsrun::{Interpreter, StepResult};

fn run_to_completion(interp: &mut Interpreter) -> Option<f64> {
    loop {
        match interp.step().ok()? {
            StepResult::Continue => continue,
            StepResult::Complete(val) => return val.as_number(),
            StepResult::NeedImports(_) => return None, // would need module loading
            StepResult::Suspended { .. } => return None, // would need async handling
            StepResult::Done => return None,
        }
    }
}

let mut interp = Interpreter::new();
interp.prepare("2 ** 10", None).unwrap();
assert_eq!(run_to_completion(&mut interp), Some(1024.0));

Variants§

§

Continue

Executed one instruction, more to execute. Call step() again to continue.

§

Complete(RuntimeValue)

Execution completed with a final value.

§

NeedImports(Vec<ImportRequest>)

Need these modules before execution can continue. Call provide_module() for each import, then call step() again.

§

Suspended

Execution suspended waiting for orders to be fulfilled. Call fulfill_orders() with responses, then call step() again.

Fields

§pending: Vec<Order>

Orders waiting for fulfillment

§cancelled: Vec<OrderId>

Orders that were cancelled (e.g., Promise.race loser)

§

Done

No active execution to step. Call prepare() first to start execution.

Trait Implementations§

Source§

impl Debug for StepResult

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.

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