diff options
Diffstat (limited to 'src/operation.rs')
| -rw-r--r-- | src/operation.rs | 30 |
1 files changed, 30 insertions, 0 deletions
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<Operator> +} + +impl Operation { + pub fn new(sign: char, func: Box<Operator>) -> 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)), + )*] + }; +} |