use std::collections::HashMap;
type Map = HashMap<String,Vec<String>>;
fn show(table: &Map){
for (artist,works) in table{
println!("the artis {}",artist);
for work in works{
println!(" {}",work);
}
}
}
fn main() {
let mut table = Map::new();
table.insert("A".to_string(),vec!["apple".to_string(),"bananaer".to_string()]
);
table.insert("bw".to_string(),
vec!["we".to_string(),"dr".to_string()]);
table.insert("ce".to_string(),
vec!["cd".to_string(),"ede".to_string()]);
show(&table);
}```
运行结果:
the artis ce
cd
ede
the artis bw
we
dr
the artis A
apple
bananaer
Rust HashMap 的使用
最新推荐文章于 2023-04-01 12:00:54 发布