Logo

Programming-Idioms

History of Idiom 54 > diff from v38 to v39

Edit summary for version 39 by nadir_:
[Rust] Iter::sum() has been stable since 1.12.0

Version 38

2019-10-14, 12:25:32

Version 39

2019-12-31, 18:41:13

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Code
let mut s=0;
for &i in &x
{
    s+=i;
}
Code
x.iter().sum()
Comments bubble
`x.iter().sum()` is currently unstable.
Doc URL
https://doc.rust-lang.org/std/iter/trait.Sum.html#tymethod.sum
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=75a6e56ab9f70c6056f18d7bbf6ed215