2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
|
|
|
|
2015-01-31 12:20:46 -05:00
|
|
|
fn iter_vec<T, F>(v: Vec<T> , mut f: F) where F: FnMut(&T) { for x in &v { f(x); } }
|
2011-07-25 16:57:27 -07:00
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2015-03-03 10:42:26 +02:00
|
|
|
let v = vec![1, 2, 3, 4, 5, 6, 7];
|
|
|
|
let mut odds = 0;
|
2012-06-30 16:19:07 -07:00
|
|
|
iter_vec(v, |i| {
|
2013-02-21 19:10:33 -08:00
|
|
|
if *i % 2 == 1 {
|
2011-12-22 14:42:52 -08:00
|
|
|
odds += 1;
|
|
|
|
}
|
|
|
|
});
|
2014-10-14 21:07:11 -04:00
|
|
|
println!("{}", odds);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(odds, 4);
|
2011-08-15 15:34:47 -07:00
|
|
|
}
|