pub struct Execution { /* private fields */ }Expand description
A statement program that ran to its end (execute,
execute_value): the context it left, the roots
it stored into and, from execute_value, the
value of its last expression statement.
use predicator_rs::{Context, Instructions, Key, Options, Value, execute};
let program = Instructions::from_json(r#"[["lit","x"],["lit",1],["store",1]]"#)?;
let execution = execute(&program, &Context::new(), &Options::new())?;
assert_eq!(execution.context().get(&Key::from("x")), Some(&Value::from(1)));
assert_eq!(execution.stored_roots(), [Key::from("x")]);
assert_eq!(execution.value(), None);Implementations§
Source§impl Execution
impl Execution
Sourcepub fn context(&self) -> &Context
pub fn context(&self) -> &Context
The context the program left: the one it was given with every write it made. The context passed in is never changed.
use predicator_rs::{Context, Key, Options, Value, execute};
let execution = execute("x = 1", &Context::new(), &Options::new())?;
let x = execution.context().get(&Key::from("x"));
assert_eq!(x, Some(&Value::from(1)));Sourcepub fn into_context(self) -> Context
pub fn into_context(self) -> Context
The context the program left, taken.
use predicator_rs::{Context, Key, Options, Value, execute};
let execution = execute("x = 1", &Context::new(), &Options::new())?;
let mut context = execution.into_context();
context.insert("y", Value::from(2));
assert_eq!(context.get(&Key::from("x")), Some(&Value::from(1)));Sourcepub fn value(&self) -> Option<&Value>
pub fn value(&self) -> Option<&Value>
The value of the program’s last expression statement (what its last
pop discarded, undefined when it popped nothing), when
execute_value made the run; None when
execute made it.
use predicator_rs::{Context, Options, Value, execute, execute_value};
let options = Options::new();
let kept = execute_value("x = 1; x + 1", &Context::new(), &options)?;
assert_eq!(kept.value(), Some(&Value::from(2)));
let dropped = execute("x = 1; x + 1", &Context::new(), &options)?;
assert_eq!(dropped.value(), None);Sourcepub fn stored_roots(&self) -> &[Key]
pub fn stored_roots(&self) -> &[Key]
The roots the program stored into, each once, in the order of its first store, whether or not the store changed the value there.
use predicator_rs::{Context, Key, Options, execute};
let program = "b = 1; a = 2; b = 3";
let execution = execute(program, &Context::new(), &Options::new())?;
assert_eq!(execution.stored_roots(), [Key::from("b"), Key::from("a")]);Trait Implementations§
impl StructuralPartialEq for Execution
Auto Trait Implementations§
impl Forget for Execution
impl Freeze for Execution
impl Move for Execution
impl RefUnwindSafe for Execution
impl Send for Execution
impl Sync for Execution
impl Unpin for Execution
impl UnsafeUnpin for Execution
impl UnwindSafe for Execution
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