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