Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

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:

text
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());
}