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
Done
No active execution to step.
Call prepare() first to start execution.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StepResult
impl !RefUnwindSafe for StepResult
impl !Send for StepResult
impl !Sync for StepResult
impl Unpin for StepResult
impl !UnwindSafe for StepResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more