Skip to content

Instantly share code, notes, and snippets.

@reem
Created June 11, 2014 02:44
Show Gist options
  • Save reem/8d3b491c4bdca2bebc57 to your computer and use it in GitHub Desktop.
Save reem/8d3b491c4bdca2bebc57 to your computer and use it in GitHub Desktop.
// 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