haar_lib/macros/
impl_algebra.rs1#[macro_export]
8macro_rules! impl_algebra {
9 (@inner [$($bound:tt)*]; $t:ty;) => {
10 impl <$($bound)*> Set for $t {}
11 };
12 (@inner [$($bound:tt)*]; $t:ty; op: $f:expr; $($rest:tt)*) => {
13 impl <$($bound)*> BinaryOp for $t {
14 fn op(self, b: Self) -> Self {
15 $f(self, b)
16 }
17 }
18 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
19 };
20 (@inner [$($bound:tt)*]; $t:ty; id: $f:expr; $($rest:tt)*) => {
21 impl <$($bound)*> Identity for $t {
22 fn id() -> Self {
23 $f
24 }
25 }
26 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
27 };
28 (@inner [$($bound:tt)*]; $t:ty; inv: $f:expr; $($rest:tt)*) => {
29 impl <$($bound)*> Inverse for $t {
30 fn inv(self) -> Self {
31 $f(self)
32 }
33 }
34 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
35 };
36 (@inner [$($bound:tt)*]; $t:ty; commu; $($rest:tt)*) => {
37 impl <$($bound)*> Commutative for $t {}
38 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
39 };
40 (@inner [$($bound:tt)*]; $t:ty; assoc; $($rest:tt)*) => {
41 impl <$($bound)*> Associative for $t {}
42 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
43 };
44 (@inner [$($bound:tt)*]; $t:ty; idem; $($rest:tt)*) => {
45 impl <$($bound)*> Idempotence for $t {}
46 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
47 };
48
49 ([$($bound:tt)*]; $t:ty; $($rest:tt)*) => {
50 impl_algebra!(@inner [$($bound)*]; $t; $($rest)*);
51 };
52 ($t:ty; $($rest:tt)*) => {
53 impl_algebra!(@inner []; $t; $($rest)*);
54 };
55}