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