fixed_bigint/fixeduint/
iter_impl.rs

1use super::{FixedUInt, MachineWord};
2use num_traits::{One, Zero};
3
4impl<T: MachineWord, const N: usize> core::iter::Sum for FixedUInt<T, N> {
5    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
6        iter.fold(Self::zero(), |acc, x| acc + x)
7    }
8}
9
10impl<'a, T: MachineWord, const N: usize> core::iter::Sum<&'a Self> for FixedUInt<T, N> {
11    fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
12        iter.fold(Self::zero(), |acc, x| acc + *x)
13    }
14}
15
16impl<T: MachineWord, const N: usize> core::iter::Product for FixedUInt<T, N> {
17    fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
18        iter.fold(Self::one(), |acc, x| acc * x)
19    }
20}
21
22impl<'a, T: MachineWord, const N: usize> core::iter::Product<&'a Self> for FixedUInt<T, N> {
23    fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
24        iter.fold(Self::one(), |acc, x| acc * *x)
25    }
26}