Professional Documents
Culture Documents
Hashmap Demo
Hashmap Demo
// collect() demo
pub fn demo11() {
let mut scores = HashMap::new();
scores.insert(String::from("Blue"), 10);
println!("{:?}", scores);
println!("{:?}", scores);
}
// ownship demo
pub fn demo12() {
let key = String::from("favorite color");
println!("{:?}", map);
println!("key is {}, value is {}.", key, value); // borrow of moved value(if
not &).
}
// get() demo
pub fn demo13() {
let mut scores = HashMap::new();
scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Yellow"), 50);
match res1 {
Some(v) => println!("Team {} scores {}.", acq1, v),
None => println!("Team {} doesn't exist.", acq1)
}
match res2 {
Some(v) => println!("Team {} scores {}.", acq2, v),
None => println!("Team {} doesn't exist.", acq2)
}
// traverse demo
pub fn demo14() {
let mut scores = HashMap::new();
scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Yellow"), 50);