rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
731 stars 135 forks source link

Add `CheckedSum` and `CheckedProduct` traits #251

Open wainwrightmark opened 2 years ago

wainwrightmark commented 2 years ago

Closes https://github.com/rust-num/num-traits/issues/250

This adds CheckedSum and CheckedProduct traits as well as blanket implementations for them.

It also adds CheckedSumIter and CheckedProductIter traits and blanket implementations for those as that provides a much more ergonomic interface, allowing you to do:

asserteq!(Some(42), [40,2].iter().checked_sum());
asserteq!(Some(42), [40,2].into_iter().checked_sum());