From faf7abca2af028ae08d55bb51c4634f3d931057b Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 20 Oct 2020 20:51:49 +0800 Subject: [PATCH] impl core::iter::Sum for Scalar --- src/scalar.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/scalar.rs b/src/scalar.rs index a2459a95..f2359d24 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -774,6 +774,18 @@ impl PrimeField for Scalar { } } +impl core::iter::Sum for Scalar +where + T: core::borrow::Borrow, +{ + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.fold(Self::zero(), |acc, item| acc + item.borrow()) + } +} + #[test] fn test_inv() { // Compute -(q^{-1} mod 2^64) mod 2^64 by exponentiating