pub struct Context {
pub functions: HashMap<String, (Vec<String>, Box<Expression>)>,
pub variables: HashMap<String, Box<Expression>>,
pub rounding: Rounding,
pub angle_unit: AngleUnit,
pub depth_limit: DepthLimit,
}
Expand description
Contains user-defined functions and constants.
Fields§
§functions: HashMap<String, (Vec<String>, Box<Expression>)>
Function declared by the user at runtime.
variables: HashMap<String, Box<Expression>>
Variables declared by the user at runtime.
rounding: Rounding
The decimal digits to display.
angle_unit: AngleUnit
The angle unit to use.
depth_limit: DepthLimit
Depth limit for recursion control. .
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(
rounding: Rounding,
angle_unit: AngleUnit,
depth_limit: DepthLimit,
) -> Self
pub fn new( rounding: Rounding, angle_unit: AngleUnit, depth_limit: DepthLimit, ) -> Self
Generates an empty context.
Sourcepub fn join_with(&mut self, context: &Self)
pub fn join_with(&mut self, context: &Self)
Add all the functions and variables of another context to this one.
Sourcepub fn add_function(
&mut self,
identifier: String,
params: Vec<String>,
body: Box<Expression>,
)
pub fn add_function( &mut self, identifier: String, params: Vec<String>, body: Box<Expression>, )
Add a function to the user-defined ones.
Sourcepub fn add_variable(&mut self, identifier: String, expression: Box<Expression>)
pub fn add_variable(&mut self, identifier: String, expression: Box<Expression>)
Add a variable to the user-defined ones.
Sourcepub fn get_function(
&self,
identifier: &str,
) -> Option<(Vec<String>, Box<Expression>)>
pub fn get_function( &self, identifier: &str, ) -> Option<(Vec<String>, Box<Expression>)>
Returns a user-defined function given an identifier.
Sourcepub fn get_var(&self, identifier: &str) -> Option<Box<Expression>>
pub fn get_var(&self, identifier: &str) -> Option<Box<Expression>>
Returns a user-defined constant given an identifier.
Sourcepub fn is_function(&self, identifier: &str) -> bool
pub fn is_function(&self, identifier: &str) -> bool
Returns true if the identifier refers to a user-defined function.
Trait Implementations§
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