mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
15 lines
318 B
Rust
15 lines
318 B
Rust
//@ run-pass
|
|
|
|
fn iter_vec<T, F>(v: Vec<T> , mut f: F) where F: FnMut(&T) { for x in &v { f(x); } }
|
|
|
|
pub fn main() {
|
|
let v = vec![1, 2, 3, 4, 5, 6, 7];
|
|
let mut odds = 0;
|
|
iter_vec(v, |i| {
|
|
if *i % 2 == 1 {
|
|
odds += 1;
|
|
}
|
|
});
|
|
println!("{}", odds);
|
|
assert_eq!(odds, 4);
|
|
}
|