Created
April 17, 2020 08:30
-
-
Save tbarusseau/cc7c68cfa8eb4956d593191fa1d126f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn sum(vector: &mut Vec<i32>) -> i32 { | |
let mut sum = 0; | |
vector.iter_mut().map(|e| e.add(1)); | |
for item in vector { | |
sum = sum + *item | |
} | |
sum | |
} | |
fn main() { | |
let mut v = vec![1,2,3]; | |
let s = sum(&mut v); | |
println!("sum of {:?}: {}", v, s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment