学习Rust是为了什么?答案是:只是为了好玩
1.创建一个空的哈希映射
在下面的示例中,我们将跟踪个人图书审阅系统。键是书名,值是一位特定用户的评论。
fn main() {
use std::collections::HashMap;
let mut book_reviews: HashMap<String, String> = HashMap::new();
// Add book reviews
book_reviews.insert(
"Adventures of Huckleberry Finn".to_string(),
"My favorite book.".to_string(),
);
book_reviews.insert(
"Grimms' Fairy Tales".to_string(),
"Masterpiece.".to_string(),