Hi I'm going the hash maps part of The Book and keep hitting my head up against a wall trying to get around the 'cannot borrow as mutable because it is also borrowed as immutable'
. I tried to create scope for the immutable moves, I can't see what the score
variable is with either rust println!
or dbg!
I also tried to create the variable at the top of my scope by going through the compiler errors still to no avail. Can someone help me see where I'm going wrong?
fn main() {
use std::collections::HashMap;
let mut scores = HashMap::new();
//let mut score: Option<String> = Some(" ".to_string());
//let mut score: Option<&i32> = Some(&10);
{
scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Yellow"), 50);
for (key, value) in &scores {
println!("{}: {}", key, value);
}
}
let team_name = String::from("Blue");
let score = scores.get(&team_name);
{
scores.insert(String::from("Blue"), 25);
scores.entry(String::from("Blue")).or_insert(45);
scores.entry(String::from("Yellow")).or_insert(12);
scores.entry(String::from("Red")).or_insert(52);
}
println!("{:?}", &score);
println!("{:?}", &scores);
}