Struct num_parser::Context
source · [−]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: RoundingThe decimal digits to display.
angle_unit: AngleUnitThe angle unit to use.
depth_limit: DepthLimitDepth limit for recursion control. .
Implementations
sourceimpl 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 RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more