首页 rust

use std::collections::HashMap;

type AstMap = HashMap<String, (usize, bool)>;

fn main() {
    // 声明
    let mut map1 = HashMap::new();
    // 插入
    map1.insert(String::from("one"), 10);
    map1.insert(String::from("two"), 20);
    println!("{:?}", map1);
    let mut hd = AstMap::new();
    hd.insert( String::from("one"), (1, false));
    hd.insert( String::from("two"), (3, false));
    println!("{:?}", hd);
    // 查找
    if map1.contains_key("two") {
        println!("true");
    }
    // 删除
    map1.remove("two");
    println!("{:?}", map1);
    // key value
    let key = hd.keys();
    let value = hd.values();
    println!("{:?}{:?}", key, value);
    // 特定key的value
    let value1 = hd.get("one").unwrap().clone();
    println!("{:?}", value1);
    
    println!("Hello, world!");
}
{"one": 10, "two": 20}
{"two": (3, false), "one": (1, false)}
true
{"one": 10}
["two", "one"][(3, false), (1, false)]
(1, false)
Hello, world!



文章评论