amalie/unit/
macro_util.rs1macro_rules! impl_self_ref_comb {
2 ($type:ident, $op:tt, $trait:ident, $func: ident) => {
3 impl $trait<$type> for $type {
4 type Output = $type;
5
6 fn $func(self, rhs: $type) -> $type {
7 $type {
8 v: self.v $op rhs.v,
9 }
10 }
11 }
12 impl $trait<$type> for &$type {
13 type Output = $type;
14
15 fn $func(self, rhs: $type) -> $type {
16 $type {
17 v: &self.v $op rhs.v,
18 }
19 }
20 }
21 impl $trait<&$type> for $type {
22 type Output = $type;
23
24 fn $func(self, rhs: &$type) -> $type {
25 $type {
26 v: self.v $op &rhs.v,
27 }
28 }
29 }
30 impl $trait<&$type> for &$type {
31 type Output = $type;
32
33 fn $func(self, rhs: &$type) -> $type {
34 $type {
35 v: &self.v $op &rhs.v,
36 }
37 }
38 }
39 }
40}
41pub(crate) use impl_self_ref_comb;
42
43macro_rules! impl_lhs_ref_comb {
44 ($type:ident, $op:tt, $trait:ident, $func: ident, $lhs: ident) => {
45 impl $trait<$type> for $lhs {
46 type Output = $type;
47
48 fn $func(self, rhs: $type) -> $type {
49 $type {
50 v: ZZ::from(self).v $op rhs.v,
51 }
52 }
53 }
54 impl $trait<$type> for &$lhs {
55 type Output = $type;
56
57 fn $func(self, rhs: $type) -> $type {
58 $type {
59 v: ZZ::from(*self).v $op rhs.v,
60 }
61 }
62 }
63 impl $trait<&$type> for $lhs {
64 type Output = $type;
65
66 fn $func(self, rhs: &$type) -> $type {
67 $type {
68 v: ZZ::from(self).v $op &rhs.v,
69 }
70 }
71 }
72 impl $trait<&$type> for &$lhs {
73 type Output = $type;
74
75 fn $func(self, rhs: &$type) -> $type {
76 $type {
77 v: &ZZ::from(*self).v $op &rhs.v,
78 }
79 }
80 }
81 }
82}
83pub(crate) use impl_lhs_ref_comb;
84
85macro_rules! impl_rhs_ref_comb {
86 ($type:ident, $op:tt, $trait:ident, $func: ident, $rhs: ident) => {
87 impl $trait<$rhs> for $type {
88 type Output = $type;
89
90 fn $func(self, rhs: $rhs) -> $type {
91 $type {
92 v: self.v $op ZZ::from(rhs).v,
93 }
94 }
95 }
96 impl $trait<$rhs> for &$type {
97 type Output = $type;
98
99 fn $func(self, rhs: $rhs) -> $type {
100 $type {
101 v: &self.v $op ZZ::from(rhs).v,
102 }
103 }
104 }
105 impl $trait<&$rhs> for $type {
106 type Output = $type;
107
108 fn $func(self, rhs: &$rhs) -> $type {
109 $type {
110 v: self.v $op &ZZ::from(*rhs).v,
111 }
112 }
113 }
114 impl $trait<&$rhs> for &$type {
115 type Output = $type;
116
117 fn $func(self, rhs: &$rhs) -> $type {
118 $type {
119 v: &self.v $op &ZZ::from(*rhs).v,
120 }
121 }
122 }
123 }
124}
125pub(crate) use impl_rhs_ref_comb;
126
127macro_rules! impl_self_ref_comb_assign {
128 ($type:ident, $op:tt, $trait: ident, $func: ident) => {
129 impl $trait<$type> for $type {
130 fn $func(&mut self, rhs: $type) {
131 self.v $op rhs.v;
132 }
133 }
134 impl $trait<&$type> for $type{
135 fn $func(&mut self, rhs: &$type) {
136 self.v $op &rhs.v;
137 }
138 }
139 }
140}
141pub(crate) use impl_self_ref_comb_assign;
142
143macro_rules! impl_rhs_ref_comb_assign {
144 ($type:ident, $op:tt, $trait:ident, $func: ident, $rhs: ident) => {
145 impl $trait<$rhs> for $type {
146 fn $func(&mut self, rhs: $rhs) {
147 self.v $op rhs;
148 }
149 }
150 }
151}
152pub(crate) use impl_rhs_ref_comb_assign;