0
私はSome
によって返された値を変更する方法を見つけ出すことはできません。HashMap :: getから返された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
1武装の 'match'の代わりに' if let'を使うのが好ましいです。 ['&String'の代わりに'&str'を受け入れます(https://stackoverflow.com/q/40006219/155423)。私の直感はあなたが本当に[エントリーAPI](https://stackoverflow.com/q/28512394/155423)を望んでいると言います。 – Shepmaster