mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
15 lines
255 B
Rust
15 lines
255 B
Rust
//@ run-pass
|
|
|
|
fn each<T, F>(x: &[T], mut f: F) where F: FnMut(&T) {
|
|
for val in x {
|
|
f(val)
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut sum = 0_usize;
|
|
let elems = [ 1_usize, 2, 3, 4, 5 ];
|
|
each(&elems, |val| sum += *val);
|
|
assert_eq!(sum, 15);
|
|
}
|