Complete the code to create an empty hash map in Rust.
let mut scores = std::collections::HashMap::[1]();The HashMap::new() function creates an empty hash map in Rust.
Complete the code to insert a key-value pair into the hash map.
scores.[1]("Blue", 10);
The insert method adds a key-value pair to a HashMap in Rust.
Fix the error in the code to get the value for a key from the hash map.
let score = scores.[1]("Blue");
The get method returns an Option with the value for the given key in a HashMap.
Fill both blanks to check if a key exists and then print its value.
if scores.[1]("Blue") { println!("Score: {}", scores.[2]("Blue").unwrap()); }
contains_key checks if the key exists, and get retrieves the value.
Fill all three blanks to create a hash map from a vector of tuples and print all key-value pairs.
let teams = vec![("Blue", 10), ("Yellow", 50)]; let scores: std::collections::HashMap<_, _> = teams.[1]().[2](); for (key, value) in scores.[3]() { println!("{}: {}", key, value); }
into_iter converts the vector into an iterator, collect gathers items into a HashMap, and iter iterates over key-value pairs.
