2013-07-30 20:46:40 -05:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-02-19 21:29:58 -06:00
|
|
|
extern crate collections;
|
|
|
|
|
2014-05-29 21:03:06 -05:00
|
|
|
use std::collections::HashMap;
|
2013-07-30 20:46:40 -05:00
|
|
|
|
2013-09-25 02:43:37 -05:00
|
|
|
pub fn main() {
|
2013-07-30 20:46:40 -05:00
|
|
|
let mut h = HashMap::new();
|
2014-04-21 16:58:52 -05:00
|
|
|
let kvs = [(1i, 10i), (2i, 20i), (3i, 30i)];
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(k,v) in kvs.iter() {
|
2013-07-30 20:46:40 -05:00
|
|
|
h.insert(k,v);
|
|
|
|
}
|
2014-04-21 16:58:52 -05:00
|
|
|
let mut x = 0i;
|
|
|
|
let mut y = 0i;
|
2013-08-03 11:45:23 -05:00
|
|
|
for (&k,&v) in h.iter() {
|
2013-07-30 20:46:40 -05:00
|
|
|
x += k;
|
|
|
|
y += v;
|
|
|
|
}
|
|
|
|
assert_eq!(x, 6);
|
|
|
|
assert_eq!(y, 60);
|
2013-09-25 02:43:37 -05:00
|
|
|
}
|