blob: bcf6510d6536f8a8c6ccc192c5b3d6600da2aaa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)),
)*]
};
}
|