Boosted by rust@mas.to ("Rust tips"):
janriemer@floss.social ("Jan :rust: :ferris:") wrote:
@bbelderbos Nice! 🤓
Did you know that the `sum` method is actually a trait method of the `Sum` trait?
https://doc.rust-lang.org/std/iter/trait.Sum.html#tymethod.sum
The `Sum` trait is also implemented for e.g. `Option`, where `T` is itself implementing `Sum`:
https://doc.rust-lang.org/std/option/enum.Option.html#impl-Sum%3COption%3CU%3E%3E-for-Option%3CT%3E
Example:
```rust
let sum_opt: Option<_> = [Some(1), Some(2), Some(3)].into_iter().sum();
assert_eq!(sum_opt, Some(6))```
Playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f9b8abf1a11cae316d0c64e8614325b5