pub struct Context { /* private fields */ }Expand description
The variables an evaluation reads: each root name bound to a value. A
load reads a root by its string name; a name the context does not bind
is unbound, which is not the same as a name bound to
Value::Undefined.
Every bound value is checked against the value domain when an
evaluation starts: a float that is not finite (non_finite_number) and
lists and maps nested past 100 levels (depth_limit_exceeded) are
refused with an EvaluationError.
use predicator_rs::{Context, Map, Value};
let mut context = Context::new();
context.insert("score", Value::from(90));
let bindings: Map = [("score", Value::from(90))].into_iter().collect();
assert_eq!(context, Context::from(bindings));Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> Context
pub fn new() -> Context
An empty context.
use predicator_rs::{Context, Key};
assert_eq!(Context::new().get(&Key::from("x")), None);Sourcepub fn insert(&mut self, name: impl Into<Key>, value: Value) -> Option<Value>
pub fn insert(&mut self, name: impl Into<Key>, value: Value) -> Option<Value>
Binds name to value, answering the value it replaces.
use predicator_rs::{Context, Value};
let mut context = Context::new();
assert_eq!(context.insert("x", Value::from(1)), None);
assert_eq!(context.insert("x", Value::from(2)), Some(Value::from(1)));Sourcepub fn get(&self, key: &Key) -> Option<&Value>
pub fn get(&self, key: &Key) -> Option<&Value>
The value bound to key, if the context binds it: how a caller reads
the context a statement program leaves (execute).
use predicator_rs::{Context, Key, Value};
let mut context = Context::new();
context.insert("score", Value::from(90));
assert_eq!(context.get(&Key::from("score")), Some(&Value::from(90)));
assert_eq!(context.get(&Key::from("other")), None);Trait Implementations§
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Forget for Context
impl Freeze for Context
impl Move for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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