insert
を2回使う
hashmap.insert(String::from("Blue"), 10);
hashmap.insert(String::from("Blue"), 50);
println!("{:?}", hashmap) // {"Blue": 50}
もしくはget_mut
を使う
let key = String::from("Blue");
if let Some(v) = hashmap.get_mut(&key) {
*v=100;
}
if let Some(v) = hashmap.get(&key) {
println!("{}", v); //100
}