pub struct Context { /* private fields */ }
Expand description
The context for evaluating expressions and statements in.
Maps names to functions and values.
Implementations§
Source§impl Context
impl Context
Sourcepub fn add_scope(&mut self, values: HashMap<String, Number>)
pub fn add_scope(&mut self, values: HashMap<String, Number>)
Add a new scope of values to the context.
Sourcepub fn lookup_value(&self, name: &str) -> CalcResult
pub fn lookup_value(&self, name: &str) -> CalcResult
Lookup a value in the context. Returns the CalcError::NameNotFound if the name is not mapped in the context (in any scope). If the name is in multiple scopes it returns the value from the last scope.
Sourcepub fn lookup_fn(&self, name: &str) -> Result<CalcFuncRef<'_>, CalcError>
pub fn lookup_fn(&self, name: &str) -> Result<CalcFuncRef<'_>, CalcError>
Lookup a function in the context. Returns the CalcError::NameNotFound if the name is not mapped in the context (in any scope). If the name is in multiple scopes it returns the value from the last scope.
Sourcepub fn bind_value(&mut self, name: String, value: Number) -> CalcResult
pub fn bind_value(&mut self, name: String, value: Number) -> CalcResult
Bind value
to name
in the top scope. If name
is the name of a builtin value nothing
will be bound and the function will return CalcError::NameAlreadyBound.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more