Files
rust/Common-Use/hashmap.rs
2025-10-05 23:51:24 +08:00

26 lines
646 B
Rust

use std::collections::HashMap;
fn thereisnoerror() {
let mut map = std::collections::HashMap::new();
map.insert("key1", "value1");
map.insert("key2", "value2");
println!("{:?}", map);
}
fn main(){
let mut h = HashMap::new();
h.insert(1, "one");
h.insert(2, "two");
h.insert(3, "three");
h.insert(4, "four");
h.insert(5, "five");
print!("{:?} ", h);
//println!("{0}", *h.count(4));
let mut a = |y: i64| -> i64 { return 1 + y; };
let result = a(3);
println!("{}", result);
match h.get(&4) {
Some(v) => println!("Found: {}", v),
None => println!("Not Found"),
}
}