pub struct Calculator;Expand description
Calculator engine that parses and evaluates DSL programs
Implementations§
Source§impl Calculator
impl Calculator
Sourcepub fn evaluate(&self, source: &str) -> Result<CalcResult>
pub fn evaluate(&self, source: &str) -> Result<CalcResult>
Parse and evaluate a calculator DSL program
§Example
use helix::operators::math::Calculator;
let calc = Calculator::new();
let src = r#"
reproducibility {
a = 2
b = 2
c = a x b
d = @c #4
}
"#;
let result = calc.evaluate(src).unwrap();
assert_eq!(result.env["a"], 2);
assert_eq!(result.env["b"], 2);
assert_eq!(result.env["c"], 4); // 2 * 2
assert_eq!(result.env["d"], 0); // 4 % 4Auto Trait Implementations§
impl Freeze for Calculator
impl RefUnwindSafe for Calculator
impl Send for Calculator
impl Sync for Calculator
impl Unpin for Calculator
impl UnwindSafe for Calculator
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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