Exerpad
🔥 0
0 XP
Exercise 6 · Chapter: HashMapsRequired+50 XP

Fix the Insert

This code tries to add items to a HashMap, but it won't compile! The HashMap isn't mutable, so Rust won't let us insert into it.

Fix the code so it prints:

Items: 3

Hint: To change a HashMap (like adding items), you need to declare it as mut!

rust
use std::collections::HashMap;

fn main() {
let colors = HashMap::new();
colors.insert("sky", "blue");
colors.insert("grass", "green");
colors.insert("sun", "yellow");
println!("Items: {}", colors.len());
}
Output
Run your code to see the output here.