I am getting those two errors when I tried to change the values in HashMap, I tried different ways, none worked. Not sure how to fix it.
error[E0594]: cannot assign to `p1.name` which is behind a `&` reference
--> src/main.rs:73:5
|
73 | p1.name = "Yujio".to_string();
| ^^^^^^^ cannot assign
error[E0596]: cannot borrow `p1.jobs` as mutable, as it is behind a `&` reference
--> src/main.rs:74:5
|
74 | p1.jobs.push("CEO".to_string());
| ^^^^^^^ cannot borrow as mutable
use std::collections::HashMap;
struct Person {
name: String,
jobs: Vec<String>,
}
fn get_person_map() -> HashMap<u32, Person> {
let mut h = HashMap::new();
h.insert(1,
Person {
name: "Mikya".to_string(),
jobs: vec!["manager".to_string(), "VP".to_string()],
});
return h;
}
fn main() {
let mut h = get_person_map();
let mut p1 = &mut h.get(&1).unwrap();
p1.name = "Yujio".to_string();
p1.jobs.push("CEO".to_string());
}