pub struct VmExecution<T> { /* private fields */ }Expand description
The execution environment for a virtual machine.
When an execution is dropped, the stack of the stack of the head machine will be cleared.
Implementations§
Source§impl<T> VmExecution<T>
impl<T> VmExecution<T>
Source§impl<T> VmExecution<T>
impl<T> VmExecution<T>
Sourcepub fn into_generator(self) -> VmGenerator<T>
pub fn into_generator(self) -> VmGenerator<T>
Coerce the current execution into a generator if appropriate.
use rune::Vm;
use rune::sync::Arc;
let mut sources = rune::sources! {
entry => {
pub fn main() {
yield 1;
yield 2;
}
}
};
let unit = rune::prepare(&mut sources).build()?;
let unit = Arc::try_new(unit)?;
let mut vm = Vm::without_runtime(unit)?;
let mut generator = vm.execute(["main"], ())?.into_generator();
let mut n = 1i64;
while let Some(value) = generator.next()? {
let value: i64 = rune::from_value(value)?;
assert_eq!(value, n);
n += 1;
}Sourcepub fn into_stream(self) -> VmStream<T>
pub fn into_stream(self) -> VmStream<T>
Coerce the current execution into a stream if appropriate.
use rune::Vm;
use rune::sync::Arc;
let mut sources = rune::sources! {
entry => {
pub async fn main() {
yield 1;
yield 2;
}
}
};
let unit = rune::prepare(&mut sources).build()?;
let unit = Arc::try_new(unit)?;
let mut vm = Vm::without_runtime(unit)?;
let mut stream = vm.execute(["main"], ())?.into_stream();
let mut n = 1i64;
while let Some(value) = stream.next().await? {
let value: i64 = rune::from_value(value)?;
assert_eq!(value, n);
n += 1;
}Source§impl<T> VmExecution<T>
impl<T> VmExecution<T>
Sourcepub fn complete(&mut self) -> Result<Value, VmError>
pub fn complete(&mut self) -> Result<Value, VmError>
Synchronously complete the current execution.
§Errors
If anything except the completion of the execution is encountered, this will result in an error.
To handle other outcomes and more configurability see
VmExecution::resume.
Sourcepub async fn async_complete(&mut self) -> Result<Value, VmError>
pub async fn async_complete(&mut self) -> Result<Value, VmError>
Asynchronously complete the current execution.
§Errors
If anything except the completion of the execution is encountered, this will result in an error.
To handle other outcomes and more configurability see
VmExecution::resume.
Sourcepub fn resume(&mut self) -> VmResume<'_, 'static, T> ⓘ
pub fn resume(&mut self) -> VmResume<'_, 'static, T> ⓘ
Resume the current execution.
To complete this operation synchronously, use VmResume::complete.
§Resume with a value
To resume an execution with a value, use VmResume::with_value. This
requires that the execution has yielded first, otherwise an error will
be produced.
§Resume with diagnostics
To associated VmDiagnostics with the execution, use
VmResume::with_diagnostics.
Source§impl VmExecution<&mut Vm>
impl VmExecution<&mut Vm>
Sourcepub fn into_owned(self) -> VmExecution<Vm>
pub fn into_owned(self) -> VmExecution<Vm>
Convert the current execution into one which owns its virtual machine.