Expand description
Trait to represent types that can be created by summing up an iterator.
This trait is used to implement Iterator::sum()
. Types which implement
this trait can be generated by using the sum()
method on an iterator.
Like FromIterator
, this trait should rarely be called directly.
Required methods
Implementations on Foreign Types
sourceimpl<const LANES: usize> Sum<Simd<u32, LANES>> for Simd<u32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> Sum<Simd<u32, LANES>> for Simd<u32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> Sum<Simd<u8, LANES>> for Simd<u8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> Sum<Simd<u8, LANES>> for Simd<u8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<i16, LANES>> for Simd<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<i16, LANES>> for Simd<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> Sum<Simd<i32, LANES>> for Simd<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> Sum<Simd<i32, LANES>> for Simd<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<f32, LANES>> for Simd<f32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<f32, LANES>> for Simd<f32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<i32, LANES>> for Simd<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<i32, LANES>> for Simd<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<usize, LANES>> for Simd<usize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<usize, LANES>> for Simd<usize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> Sum<Simd<i64, LANES>> for Simd<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> Sum<Simd<i64, LANES>> for Simd<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> Sum<Simd<isize, LANES>> for Simd<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> Sum<Simd<isize, LANES>> for Simd<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<i8, LANES>> for Simd<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<i8, LANES>> for Simd<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<i64, LANES>> for Simd<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<i64, LANES>> for Simd<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<isize, LANES>> for Simd<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<isize, LANES>> for Simd<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> Sum<Simd<f32, LANES>> for Simd<f32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> Sum<Simd<f32, LANES>> for Simd<f32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<u32, LANES>> for Simd<u32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<u32, LANES>> for Simd<u32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<'a, const LANES: usize> Sum<&'a Simd<u64, LANES>> for Simd<u64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<'a, const LANES: usize> Sum<&'a Simd<u64, LANES>> for Simd<u64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.37.0 · sourceimpl<T, U> Sum<Option<U>> for Option<T> where
T: Sum<U>,
impl<T, U> Sum<Option<U>> for Option<T> where
T: Sum<U>,
sourcepub fn sum<I>(iter: I) -> Option<T> where
I: Iterator<Item = Option<U>>,
pub fn sum<I>(iter: I) -> Option<T> where
I: Iterator<Item = Option<U>>,
Takes each element in the Iterator
: if it is a None
, no further
elements are taken, and the None
is returned. Should no None
occur, the sum of all elements is returned.
Examples
This sums up the position of the character ‘a’ in a vector of strings,
if a word did not have the character ‘a’ the operation returns None
:
let words = vec!["have", "a", "great", "day"];
let total: Option<usize> = words.iter().map(|w| w.find('a')).sum();
assert_eq!(total, Some(5));