2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-05-30 02:03:06 +00:00
|
|
|
use std::collections::HashMap;
|
2013-07-31 01:46:40 +00:00
|
|
|
|
|
|
|
// This is a fancy one: it uses an external iterator established
|
|
|
|
// outside the loop, breaks, then _picks back up_ and continues
|
|
|
|
// iterating with it.
|
|
|
|
|
2013-09-25 07:43:37 +00:00
|
|
|
pub fn main() {
|
2013-07-31 01:46:40 +00:00
|
|
|
let mut h = HashMap::new();
|
2015-01-25 21:05:03 +00:00
|
|
|
let kvs = [(1, 10), (2, 20), (3, 30)];
|
2015-01-31 17:20:46 +00:00
|
|
|
for &(k,v) in &kvs {
|
2013-07-31 01:46:40 +00:00
|
|
|
h.insert(k,v);
|
|
|
|
}
|
|
|
|
let mut x = 0;
|
|
|
|
let mut y = 0;
|
|
|
|
|
|
|
|
let mut i = h.iter();
|
|
|
|
|
2015-01-23 01:08:56 +00:00
|
|
|
for (&k,&v) in i.by_ref() {
|
2013-07-31 01:46:40 +00:00
|
|
|
x += k;
|
|
|
|
y += v;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-03 16:45:23 +00:00
|
|
|
for (&k,&v) in i {
|
2013-07-31 01:46:40 +00:00
|
|
|
x += k;
|
|
|
|
y += v;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(x, 6);
|
|
|
|
assert_eq!(y, 60);
|
2013-09-25 07:43:37 +00:00
|
|
|
}
|