gw_rust_programming_tutorial/chapter_8/
test_map.rs1use std::collections::HashMap;
2
3pub fn test_hash_map() {
4 let mut scores = HashMap::new();
6
7 scores.insert(String::from("Blue"), 10);
8 scores.insert(String::from("Yellow"), 50);
9 scores.entry(String::from("Blue")).or_insert(30);
11
12 let teams = vec![String::from("Blue"), String::from("Yellow")];
14 let initial_scores = vec![10, 50];
15
16 let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect();
17
18 println!("map={:?}",scores);
19
20 test_cus_hash_map();
21}
22
23fn test_cus_hash_map(){
24 let mut mapCus:HashMap<i32,i32>=HashMap::new();
25 mapCus.insert(1,2);
26 mapCus.insert(2,2);
27
28 println!("{:?}",mapCus);
29
30}