Struct Context

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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

Source

pub fn assign_var(&mut self, query: &String, val: f64) -> Result<(), CalcError>

This function triest to assign a value to variable, returning an empty Ok if successful, otherwise an Err

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.