我无法弄清楚如何修改Some
返回的值:
fn add_employee(
employees: &mut HashMap<String, Vec<String>>,
employee_name: &String,
department_name: &String,
) {
match employees.get(department_name) {
Some(members) => {
members.push(employee_name.clone()); // what I want, but it doesn't work
}
None => {}
}
}
编译器抱怨:
error[E0596]: cannot borrow immutable borrowed content `*members` as mutable
--> src/main.rs:10:13
|
10 | members.push(employee_name.clone());
| ^^^^^^^ cannot borrow as mutable