halo2curves/derive/
mod.rs#[macro_use]
pub mod curve;
#[macro_use]
pub mod field;
#[macro_use]
pub mod pairing;
#[macro_export]
macro_rules! impl_binops_calls {
($field:ident) => {
impl ::core::ops::Neg for $field {
type Output = $field;
#[inline]
fn neg(self) -> $field {
-&self
}
}
impl<'a> ::core::ops::Neg for &'a $field {
type Output = $field;
#[inline]
fn neg(self) -> $field {
self.neg()
}
}
impl<'a, 'b> ::core::ops::Sub<&'b $field> for &'a $field {
type Output = $field;
#[inline]
fn sub(self, rhs: &'b $field) -> $field {
self.sub(rhs)
}
}
impl<'a, 'b> ::core::ops::Add<&'b $field> for &'a $field {
type Output = $field;
#[inline]
fn add(self, rhs: &'b $field) -> $field {
self.add(rhs)
}
}
impl<'a, 'b> ::core::ops::Mul<&'b $field> for &'a $field {
type Output = $field;
#[inline]
fn mul(self, rhs: &'b $field) -> $field {
self.mul(rhs)
}
}
};
}
#[macro_export]
macro_rules! impl_add_binop_specify_output {
($lhs:ident, $rhs:ident, $output:ident) => {
impl<'b> ::core::ops::Add<&'b $rhs> for $lhs {
type Output = $output;
#[inline]
fn add(self, rhs: &'b $rhs) -> $output {
&self + rhs
}
}
impl<'a> ::core::ops::Add<$rhs> for &'a $lhs {
type Output = $output;
#[inline]
fn add(self, rhs: $rhs) -> $output {
self + &rhs
}
}
impl ::core::ops::Add<$rhs> for $lhs {
type Output = $output;
#[inline]
fn add(self, rhs: $rhs) -> $output {
&self + &rhs
}
}
};
}
#[macro_export]
macro_rules! impl_sub_binop_specify_output {
($lhs:ident, $rhs:ident, $output:ident) => {
impl<'b> ::core::ops::Sub<&'b $rhs> for $lhs {
type Output = $output;
#[inline]
fn sub(self, rhs: &'b $rhs) -> $output {
&self - rhs
}
}
impl<'a> ::core::ops::Sub<$rhs> for &'a $lhs {
type Output = $output;
#[inline]
fn sub(self, rhs: $rhs) -> $output {
self - &rhs
}
}
impl ::core::ops::Sub<$rhs> for $lhs {
type Output = $output;
#[inline]
fn sub(self, rhs: $rhs) -> $output {
&self - &rhs
}
}
};
}
#[macro_export]
macro_rules! impl_binops_additive_specify_output {
($lhs:ident, $rhs:ident, $output:ident) => {
$crate::impl_add_binop_specify_output!($lhs, $rhs, $output);
$crate::impl_sub_binop_specify_output!($lhs, $rhs, $output);
};
}
#[macro_export]
macro_rules! impl_binops_multiplicative_mixed {
($lhs:ident, $rhs:ident, $output:ident) => {
impl<'b> ::core::ops::Mul<&'b $rhs> for $lhs {
type Output = $output;
#[inline]
fn mul(self, rhs: &'b $rhs) -> $output {
&self * rhs
}
}
impl<'a> ::core::ops::Mul<$rhs> for &'a $lhs {
type Output = $output;
#[inline]
fn mul(self, rhs: $rhs) -> $output {
self * &rhs
}
}
impl ::core::ops::Mul<$rhs> for $lhs {
type Output = $output;
#[inline]
fn mul(self, rhs: $rhs) -> $output {
&self * &rhs
}
}
};
}
#[macro_export]
macro_rules! impl_binops_additive {
($lhs:ident, $rhs:ident) => {
$crate::impl_binops_additive_specify_output!($lhs, $rhs, $lhs);
impl ::core::ops::SubAssign<$rhs> for $lhs {
#[inline]
fn sub_assign(&mut self, rhs: $rhs) {
*self = &*self - &rhs;
}
}
impl ::core::ops::AddAssign<$rhs> for $lhs {
#[inline]
fn add_assign(&mut self, rhs: $rhs) {
*self = &*self + &rhs;
}
}
impl<'b> ::core::ops::SubAssign<&'b $rhs> for $lhs {
#[inline]
fn sub_assign(&mut self, rhs: &'b $rhs) {
*self = &*self - rhs;
}
}
impl<'b> ::core::ops::AddAssign<&'b $rhs> for $lhs {
#[inline]
fn add_assign(&mut self, rhs: &'b $rhs) {
*self = &*self + rhs;
}
}
};
}
#[macro_export]
macro_rules! impl_binops_multiplicative {
($lhs:ident, $rhs:ident) => {
$crate::impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs);
impl ::core::ops::MulAssign<$rhs> for $lhs {
#[inline]
fn mul_assign(&mut self, rhs: $rhs) {
*self = &*self * &rhs;
}
}
impl<'b> ::core::ops::MulAssign<&'b $rhs> for $lhs {
#[inline]
fn mul_assign(&mut self, rhs: &'b $rhs) {
*self = &*self * rhs;
}
}
};
}
#[macro_export]
macro_rules! impl_sum_prod {
($f:ident) => {
impl<T: ::core::borrow::Borrow<$f>> ::core::iter::Sum<T> for $f {
fn sum<I: Iterator<Item = T>>(iter: I) -> Self {
iter.fold(Self::zero(), |acc, item| acc + item.borrow())
}
}
impl<T: ::core::borrow::Borrow<$f>> ::core::iter::Product<T> for $f {
fn product<I: Iterator<Item = T>>(iter: I) -> Self {
iter.fold(Self::one(), |acc, item| acc * item.borrow())
}
}
};
}