diff options
Diffstat (limited to 'src/math/operation.rs')
| -rw-r--r-- | src/math/operation.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/math/operation.rs b/src/math/operation.rs new file mode 100644 index 0000000..bcf6510 --- /dev/null +++ b/src/math/operation.rs @@ -0,0 +1,32 @@ +use crate::math::complex::Complex; + +pub type Operator = fn(Complex, Complex) -> Complex; + +#[derive(Clone)] +pub struct Operation { + sign: char, + func: Operator +} + +impl Operation { + pub fn new(sign: char, func: Operator) -> Self { + Self { sign, func } + } + + pub fn sign(&self) -> char { + self.sign + } + + pub fn evaluate(&self, a: Complex, b: Complex) -> Complex { + (self.func)(a, b) + } +} + +#[macro_export] +macro_rules! operations { + {$($x:expr => $y:expr), *} => { + vec![$( + Operation::new($x, Box::new($y)), + )*] + }; +} |