Skip to content

Instantly share code, notes, and snippets.

@tbarusseau
Created April 17, 2020 08:30
Show Gist options
  • Save tbarusseau/cc7c68cfa8eb4956d593191fa1d126f8 to your computer and use it in GitHub Desktop.
Save tbarusseau/cc7c68cfa8eb4956d593191fa1d126f8 to your computer and use it in GitHub Desktop.
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