halo2curves_axiom/derive/
mod.rs

1#[macro_use]
2pub mod curve;
3#[macro_use]
4pub mod field;
5
6#[macro_export]
7macro_rules! impl_add_binop_specify_output {
8    ($lhs:ident, $rhs:ident, $output:ident) => {
9        impl<'b> ::core::ops::Add<&'b $rhs> for $lhs {
10            type Output = $output;
11
12            #[inline]
13            fn add(self, rhs: &'b $rhs) -> $output {
14                &self + rhs
15            }
16        }
17
18        impl<'a> ::core::ops::Add<$rhs> for &'a $lhs {
19            type Output = $output;
20
21            #[inline]
22            fn add(self, rhs: $rhs) -> $output {
23                self + &rhs
24            }
25        }
26
27        impl ::core::ops::Add<$rhs> for $lhs {
28            type Output = $output;
29
30            #[inline]
31            fn add(self, rhs: $rhs) -> $output {
32                &self + &rhs
33            }
34        }
35    };
36}
37
38#[macro_export]
39macro_rules! impl_sub_binop_specify_output {
40    ($lhs:ident, $rhs:ident, $output:ident) => {
41        impl<'b> ::core::ops::Sub<&'b $rhs> for $lhs {
42            type Output = $output;
43
44            #[inline]
45            fn sub(self, rhs: &'b $rhs) -> $output {
46                &self - rhs
47            }
48        }
49
50        impl<'a> ::core::ops::Sub<$rhs> for &'a $lhs {
51            type Output = $output;
52
53            #[inline]
54            fn sub(self, rhs: $rhs) -> $output {
55                self - &rhs
56            }
57        }
58
59        impl ::core::ops::Sub<$rhs> for $lhs {
60            type Output = $output;
61
62            #[inline]
63            fn sub(self, rhs: $rhs) -> $output {
64                &self - &rhs
65            }
66        }
67    };
68}
69
70#[macro_export]
71macro_rules! impl_binops_additive_specify_output {
72    ($lhs:ident, $rhs:ident, $output:ident) => {
73        impl_add_binop_specify_output!($lhs, $rhs, $output);
74        impl_sub_binop_specify_output!($lhs, $rhs, $output);
75    };
76}
77
78#[macro_export]
79macro_rules! impl_binops_multiplicative_mixed {
80    ($lhs:ident, $rhs:ident, $output:ident) => {
81        impl<'b> ::core::ops::Mul<&'b $rhs> for $lhs {
82            type Output = $output;
83
84            #[inline]
85            fn mul(self, rhs: &'b $rhs) -> $output {
86                &self * rhs
87            }
88        }
89
90        impl<'a> ::core::ops::Mul<$rhs> for &'a $lhs {
91            type Output = $output;
92
93            #[inline]
94            fn mul(self, rhs: $rhs) -> $output {
95                self * &rhs
96            }
97        }
98
99        impl ::core::ops::Mul<$rhs> for $lhs {
100            type Output = $output;
101
102            #[inline]
103            fn mul(self, rhs: $rhs) -> $output {
104                &self * &rhs
105            }
106        }
107    };
108}
109
110#[macro_export]
111macro_rules! impl_binops_additive {
112    ($lhs:ident, $rhs:ident) => {
113        impl_binops_additive_specify_output!($lhs, $rhs, $lhs);
114
115        impl ::core::ops::SubAssign<$rhs> for $lhs {
116            #[inline]
117            fn sub_assign(&mut self, rhs: $rhs) {
118                *self = &*self - &rhs;
119            }
120        }
121
122        impl ::core::ops::AddAssign<$rhs> for $lhs {
123            #[inline]
124            fn add_assign(&mut self, rhs: $rhs) {
125                *self = &*self + &rhs;
126            }
127        }
128
129        impl<'b> ::core::ops::SubAssign<&'b $rhs> for $lhs {
130            #[inline]
131            fn sub_assign(&mut self, rhs: &'b $rhs) {
132                *self = &*self - rhs;
133            }
134        }
135
136        impl<'b> ::core::ops::AddAssign<&'b $rhs> for $lhs {
137            #[inline]
138            fn add_assign(&mut self, rhs: &'b $rhs) {
139                *self = &*self + rhs;
140            }
141        }
142    };
143}
144
145#[macro_export]
146macro_rules! impl_binops_multiplicative {
147    ($lhs:ident, $rhs:ident) => {
148        impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs);
149
150        impl ::core::ops::MulAssign<$rhs> for $lhs {
151            #[inline]
152            fn mul_assign(&mut self, rhs: $rhs) {
153                *self = &*self * &rhs;
154            }
155        }
156
157        impl<'b> ::core::ops::MulAssign<&'b $rhs> for $lhs {
158            #[inline]
159            fn mul_assign(&mut self, rhs: &'b $rhs) {
160                *self = &*self * rhs;
161            }
162        }
163    };
164}
165
166#[macro_export]
167macro_rules! impl_sum_prod {
168    ($f:ident) => {
169        impl<T: ::core::borrow::Borrow<$f>> ::core::iter::Sum<T> for $f {
170            fn sum<I: Iterator<Item = T>>(iter: I) -> Self {
171                use ::ff::Field;
172                iter.fold(Self::ZERO, |acc, item| acc + item.borrow())
173            }
174        }
175
176        impl<T: ::core::borrow::Borrow<$f>> ::core::iter::Product<T> for $f {
177            fn product<I: Iterator<Item = T>>(iter: I) -> Self {
178                use ::ff::Field;
179                iter.fold(Self::ONE, |acc, item| acc * item.borrow())
180            }
181        }
182    };
183}