Created
June 11, 2014 02:44
-
-
Save reem/8d3b491c4bdca2bebc57 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
// Works: | |
fn sum<T: Zero>(list: &Vec<T>) -> T { | |
list.iter().fold(Zero::zero(), |a: T, b| a + *b) | |
} | |
// Does not work: | |
// Gives a move error on &b saying you are trying to move out | |
// of a dereference of an &-pointer. | |
fn sum<T: Zero>(list: &Vec<T>) -> T { | |
list.iter().fold(Zero::zero(), |a: T, &b| a + b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment