2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-01-02 17:32:54 -05:00
|
|
|
fn each<T, F>(x: &[T], mut f: F) where F: FnMut(&T) {
|
2015-01-31 12:20:46 -05:00
|
|
|
for val in x {
|
2014-07-23 12:43:29 -07:00
|
|
|
f(val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-02-18 05:42:01 -05:00
|
|
|
let mut sum = 0_usize;
|
|
|
|
let elems = [ 1_usize, 2, 3, 4, 5 ];
|
2014-11-17 21:39:01 +13:00
|
|
|
each(&elems, |val| sum += *val);
|
2014-07-23 12:43:29 -07:00
|
|
|
assert_eq!(sum, 15);
|
|
|
|
}
|