pasta_curves/
macros.rs
1macro_rules! impl_add_binop_specify_output {
2 ($lhs:ident, $rhs:ident, $output:ident) => {
3 impl<'b> ::core::ops::Add<&'b $rhs> for $lhs {
4 type Output = $output;
5
6 #[inline]
7 fn add(self, rhs: &'b $rhs) -> $output {
8 &self + rhs
9 }
10 }
11
12 impl<'a> ::core::ops::Add<$rhs> for &'a $lhs {
13 type Output = $output;
14
15 #[inline]
16 fn add(self, rhs: $rhs) -> $output {
17 self + &rhs
18 }
19 }
20
21 impl ::core::ops::Add<$rhs> for $lhs {
22 type Output = $output;
23
24 #[inline]
25 fn add(self, rhs: $rhs) -> $output {
26 &self + &rhs
27 }
28 }
29 };
30}
31
32macro_rules! impl_sub_binop_specify_output {
33 ($lhs:ident, $rhs:ident, $output:ident) => {
34 impl<'b> ::core::ops::Sub<&'b $rhs> for $lhs {
35 type Output = $output;
36
37 #[inline]
38 fn sub(self, rhs: &'b $rhs) -> $output {
39 &self - rhs
40 }
41 }
42
43 impl<'a> ::core::ops::Sub<$rhs> for &'a $lhs {
44 type Output = $output;
45
46 #[inline]
47 fn sub(self, rhs: $rhs) -> $output {
48 self - &rhs
49 }
50 }
51
52 impl ::core::ops::Sub<$rhs> for $lhs {
53 type Output = $output;
54
55 #[inline]
56 fn sub(self, rhs: $rhs) -> $output {
57 &self - &rhs
58 }
59 }
60 };
61}
62
63macro_rules! impl_binops_additive_specify_output {
64 ($lhs:ident, $rhs:ident, $output:ident) => {
65 impl_add_binop_specify_output!($lhs, $rhs, $output);
66 impl_sub_binop_specify_output!($lhs, $rhs, $output);
67 };
68}
69
70macro_rules! impl_binops_multiplicative_mixed {
71 ($lhs:ident, $rhs:ident, $output:ident) => {
72 impl<'b> ::core::ops::Mul<&'b $rhs> for $lhs {
73 type Output = $output;
74
75 #[inline]
76 fn mul(self, rhs: &'b $rhs) -> $output {
77 &self * rhs
78 }
79 }
80
81 impl<'a> ::core::ops::Mul<$rhs> for &'a $lhs {
82 type Output = $output;
83
84 #[inline]
85 fn mul(self, rhs: $rhs) -> $output {
86 self * &rhs
87 }
88 }
89
90 impl ::core::ops::Mul<$rhs> for $lhs {
91 type Output = $output;
92
93 #[inline]
94 fn mul(self, rhs: $rhs) -> $output {
95 &self * &rhs
96 }
97 }
98 };
99}
100
101macro_rules! impl_binops_additive {
102 ($lhs:ident, $rhs:ident) => {
103 impl_binops_additive_specify_output!($lhs, $rhs, $lhs);
104
105 impl ::core::ops::SubAssign<$rhs> for $lhs {
106 #[inline]
107 fn sub_assign(&mut self, rhs: $rhs) {
108 *self = &*self - &rhs;
109 }
110 }
111
112 impl ::core::ops::AddAssign<$rhs> for $lhs {
113 #[inline]
114 fn add_assign(&mut self, rhs: $rhs) {
115 *self = &*self + &rhs;
116 }
117 }
118
119 impl<'b> ::core::ops::SubAssign<&'b $rhs> for $lhs {
120 #[inline]
121 fn sub_assign(&mut self, rhs: &'b $rhs) {
122 *self = &*self - rhs;
123 }
124 }
125
126 impl<'b> ::core::ops::AddAssign<&'b $rhs> for $lhs {
127 #[inline]
128 fn add_assign(&mut self, rhs: &'b $rhs) {
129 *self = &*self + rhs;
130 }
131 }
132 };
133}
134
135macro_rules! impl_binops_multiplicative {
136 ($lhs:ident, $rhs:ident) => {
137 impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs);
138
139 impl ::core::ops::MulAssign<$rhs> for $lhs {
140 #[inline]
141 fn mul_assign(&mut self, rhs: $rhs) {
142 *self = &*self * &rhs;
143 }
144 }
145
146 impl<'b> ::core::ops::MulAssign<&'b $rhs> for $lhs {
147 #[inline]
148 fn mul_assign(&mut self, rhs: &'b $rhs) {
149 *self = &*self * rhs;
150 }
151 }
152 };
153}