Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Last active February 20, 2018 08:32
Show Gist options
  • Save thomwiggers/03b82e9bc4a5a869900a719e9191be02 to your computer and use it in GitHub Desktop.
Save thomwiggers/03b82e9bc4a5a869900a719e9191be02 to your computer and use it in GitHub Desktop.
// works:
assert_eq!(10, (0..10).map(|i| m.columns[i][i]).sum());
let mut acc: i32 = 0;
// works
for i in 0..10 {
for j in 0..10 {
acc += m.columns[i][j];
}
}
assert_eq!(10, acc);
// doesn't work without :i32
let acc: i32 = (0..10).map(
|i| (0..10).map(|j| m.columns[i][j]).sum(): i32
).sum();
assert_eq!(10, acc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment