gw-rust-programming-tutorial 0.1.0

gw rust test.
Documentation
use std::collections::HashMap;

pub fn test_hash_map() {
    //新建一个哈希 map
    let mut scores = HashMap::new();

    scores.insert(String::from("Blue"), 10);
    scores.insert(String::from("Yellow"), 50);
    //Entry 的 or_insert 方法在键对应的值存在时就返回这个值的可变引用,如果不存在则将参数作为新值插入并返回新值的可变引用。这比编写自己的逻辑要简明的多,另外也与借用检查器结合得更好。
    scores.entry(String::from("Blue")).or_insert(30);

    //将2个vec进行元组绑定成map
    let teams = vec![String::from("Blue"), String::from("Yellow")];
    let initial_scores = vec![10, 50];

    let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect();

    println!("map={:?}",scores);

    test_cus_hash_map();
}

fn test_cus_hash_map(){
    let mut mapCus:HashMap<i32,i32>=HashMap::new();
    mapCus.insert(1,2);
    mapCus.insert(2,2);

    println!("{:?}",mapCus);

}