Skip to content

Commit f5379ac

Browse files
Working with hashmaps
1 parent 5229ade commit f5379ac

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::collections::HashMap;
2+
3+
fn main() {
4+
let mut scores = HashMap::new();
5+
6+
7+
scores.insert(String::from("Red"), 10);
8+
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

Comments
 (0)