From 5ccc6e5ec8a433f68bfeb17e8dcedec5b62a36a9 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 17 Jan 2024 18:24:21 +0100 Subject: First sketch of matheval --- src/operation.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/operation.rs (limited to 'src/operation.rs') diff --git a/src/operation.rs b/src/operation.rs new file mode 100644 index 0000000..861fb5a --- /dev/null +++ b/src/operation.rs @@ -0,0 +1,30 @@ + +pub type Operator = dyn Fn(f64, f64) -> f64; + +pub struct Operation { + sign: char, + func: Box +} + +impl Operation { + pub fn new(sign: char, func: Box) -> Self { + Self { sign, func } + } + + pub fn sign(&self) -> char { + self.sign + } + + pub fn evaluate(&self, a: f64, b: f64) -> f64 { + (self.func)(a, b) + } +} + +#[macro_export] +macro_rules! opvec { + ($(($x:expr, $y:expr)), *) => { + vec![$( + Operation::new($x, Box::new($y)), + )*] + }; +} -- cgit v1.2.3-70-g09d2