pub struct Context {
pub prev_ans: Option<f64>,
/* private fields */
}
Expand description
Object passed to the calculate() function to track state of the calculator, including defined variables, functions, and equation history
Fields§
§prev_ans: Option<f64>
Stores the value of the last successful calculation result, used when
evaluating the ans
builtin variable;
Implementations§
Source§impl Context
impl Context
pub fn new() -> Self
Sourcepub fn lookup_var(&self, query: &String) -> Option<Result<f64, CalcError>>
pub fn lookup_var(&self, query: &String) -> Option<Result<f64, CalcError>>
Takes in a query string and returns an Option that is none if the variable doesn’t exist in the var table. The option contains a result that will be Ok with the var’s value if the var can be read from, otherwise an error.
Sourcepub fn try_function(
&self,
name: &String,
args: Vec<f64>,
) -> Option<Result<f64, CalcError>>
pub fn try_function( &self, name: &String, args: Vec<f64>, ) -> Option<Result<f64, CalcError>>
This function looks up a function with the specified name, returning a None Option if the function doesn’t exist, an Err inside the Option if there’s an issue with the arguments, otherwise it executes the function with the given arguments and returns the answer
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