2
2
3
3
//! Generic Field Traits
4
4
5
- use core:: { fmt, hash, ops} ;
5
+ use core:: { fmt, hash, iter , ops} ;
6
6
7
7
/// A generic field.
8
8
pub trait Field :
@@ -13,6 +13,8 @@ pub trait Field:
13
13
+ hash:: Hash
14
14
+ fmt:: Debug
15
15
+ fmt:: Display
16
+ + iter:: Sum
17
+ + for < ' a > iter:: Sum < & ' a Self >
16
18
+ ops:: Add < Self , Output = Self >
17
19
+ ops:: Sub < Self , Output = Self >
18
20
+ ops:: AddAssign
@@ -29,7 +31,7 @@ pub trait Field:
29
31
+ for < ' a > ops:: MulAssign < & ' a Self >
30
32
+ for < ' a > ops:: Div < & ' a Self , Output = Self >
31
33
+ for < ' a > ops:: DivAssign < & ' a Self >
32
- + ops:: Neg
34
+ + ops:: Neg < Output = Self >
33
35
{
34
36
/// The zero constant of the field.
35
37
const ZERO : Self ;
@@ -362,6 +364,19 @@ macro_rules! impl_ops_for_fe {
362
364
self . _neg( )
363
365
}
364
366
}
367
+
368
+ // sum
369
+ impl core:: iter:: Sum for $op {
370
+ fn sum<I : Iterator <Item = Self >>( iter: I ) -> Self {
371
+ iter. fold( crate :: primitives:: Field :: ZERO , |i, acc| i + acc)
372
+ }
373
+ }
374
+
375
+ impl <' s> core:: iter:: Sum <& ' s Self > for $op {
376
+ fn sum<I : Iterator <Item = & ' s Self >>( iter: I ) -> Self {
377
+ iter. fold( crate :: primitives:: Field :: ZERO , |i, acc| i + acc)
378
+ }
379
+ }
365
380
} ;
366
381
}
367
382
pub ( super ) use impl_ops_for_fe;
0 commit comments