group: Sum + for<'a> Sum<&'a Self> bounds for Group
This commit is contained in:
parent
5397d73e0b
commit
e3d84280b9
|
@ -4,6 +4,7 @@ use pairing::{Engine, PairingCurveAffine};
|
|||
|
||||
use rand_core::RngCore;
|
||||
use std::fmt;
|
||||
use std::iter::Sum;
|
||||
use std::num::Wrapping;
|
||||
use std::ops::{Add, AddAssign, BitAnd, Mul, MulAssign, Neg, Shr, Sub, SubAssign};
|
||||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
@ -47,6 +48,18 @@ impl ConditionallySelectable for Fr {
|
|||
}
|
||||
}
|
||||
|
||||
impl Sum for Fr {
|
||||
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||
iter.fold(Self::zero(), ::std::ops::Add::add)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> Sum<&'r Fr> for Fr {
|
||||
fn sum<I: Iterator<Item = &'r Fr>>(iter: I) -> Self {
|
||||
iter.fold(Self::zero(), ::std::ops::Add::add)
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Fr {
|
||||
type Output = Self;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use ff::{Field, PrimeField};
|
|||
use rand::RngCore;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::iter::Sum;
|
||||
use std::ops::{Add, AddAssign, Neg, Sub, SubAssign};
|
||||
|
||||
pub mod tests;
|
||||
|
@ -38,6 +39,8 @@ pub trait Group:
|
|||
+ Send
|
||||
+ Sync
|
||||
+ 'static
|
||||
+ Sum
|
||||
+ for<'a> Sum<&'a Self>
|
||||
+ Neg<Output = Self>
|
||||
+ GroupOps
|
||||
+ GroupOpsOwned
|
||||
|
|
|
@ -205,6 +205,18 @@ macro_rules! curve_impl {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::std::iter::Sum for $projective {
|
||||
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||
iter.fold(Self::identity(), ::std::ops::Add::add)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> ::std::iter::Sum<&'r $projective> for $projective {
|
||||
fn sum<I: Iterator<Item = &'r $projective>>(iter: I) -> Self {
|
||||
iter.fold(Self::identity(), ::std::ops::Add::add)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Neg for $projective {
|
||||
type Output = Self;
|
||||
|
||||
|
|
Loading…
Reference in New Issue