We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5229ade commit f5379acCopy full SHA for f5379ac
rustlang_book/collections/hashmaps/Cargo.toml
@@ -0,0 +1,8 @@
1
+[package]
2
+name = "hashmaps"
3
+version = "0.1.0"
4
+edition = "2021"
5
+
6
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
8
+[dependencies]
rustlang_book/collections/hashmaps/src/main.rs
@@ -0,0 +1,19 @@
+use std::collections::HashMap;
+fn main() {
+ let mut scores = HashMap::new();
+ scores.insert(String::from("Red"), 10);
+ scores.insert(String::from("Blue"), 50);
9
+ scores.insert(String::from("Yellow"), 25);
10
11
+ let team_name = String::from("Red");
12
+ let score = scores.get(&team_name).copied().unwrap_or(0);
13
+ println!("{}: {}", team_name, score);
14
15
16
+ for (team, score ) in &scores {
17
+ println!("{}: {}", team, score);
18
+ }
19
+}
0 commit comments