Struct aftermath::Context

source ·
pub struct Context {
    pub zero_precision: f64,
    /* private fields */
}

Fields§

§zero_precision: f64

Implementations§

source§

impl Context

source

pub fn new() -> Self

Creates a new empty context

source

pub fn get_reserved_names(&self) -> Vec<&str>

Get an iterator over the reserved names for this context You should only call this function once and cache its result But you can call it multiples times

source

pub fn get_binding(&self, name: &str) -> Result<&Complex64, CalcError>

Errors

Return an error if the requested binding isn’t found in this context

source

pub fn get_binding_mut(
    &mut self,
    name: &str
) -> Result<&mut Complex64, CalcError>

Errors

Return an error if the requested binding isn’t found in this context

source

pub fn get_func(
    &self,
    name: &str
) -> Result<&Arc<dyn Func + Send + Sync>, CalcError>

Errors

Return an error if the requested function isn’t found in this context

source

pub fn insert_func(
    &mut self,
    name: Cow<'static, str>,
    func: Arc<dyn Func + Send + Sync>
)

Insert the given function into the context, overwriting if the function already existed

source

pub fn insert_binding(&mut self, name: Cow<'static, str>, binding: Complex64)

Insert the given binding into the context, overwriting if the binding already existed

source

pub fn eval<'expr: 'arena, 'arena>(
    &self,
    expr: &'expr Expr<'arena>
) -> Result<Complex64, CalcError>

Evaluate an AST in the current Context

Errors

This will return an error if any of the operation return an error

source

pub fn eval_rpn<'expr: 'arena, 'arena>(
    &self,
    rpn: &'expr RpnExpr<'arena>
) -> Result<Complex64, CalcError>

Evaluate an RPN sequence in the current context

Errors

This will return an error on three separate instances: - A User-Function has returned an error - A bindings is missing in the current context - A User-Function is missing in the current context

source

pub fn is_zero(&self, f: f64) -> bool

Check that the given f64 can be considered equal to zero It uses the field zero_precision to get a range of values (-zero_precision, +zero_precision) this considered equal to zero

source

pub fn is_complex_zero(&self, c: Complex64) -> bool

Check that the given Complex number is close enough to zero to be considered equal to zero

source

pub fn is_near(&self, f: f64, to: f64) -> bool

Check if a f64 is close enough to another one to be considered equal

source

pub fn is_complex_near(&self, c: Complex64, to: Complex64) -> bool

Check if a complex number is near enough to another one to be considered equal

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Context

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Reduce for Context

source§

fn reduce(&self, expr: &mut Expr<'_>) -> Result<(), CalcError>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.