Can anybody explain why following code does not compile?
use std::collections::HashMap;
fn add(mut h: &HashMap<&str, &str>) {
h.insert("foo", "bar");
}
fn main() {
let mut h: HashMap<&str, &str> = HashMap::new();
add(&h);
println!("{:?}", h.get("foo"));
}
This is what rustc tells me
hashtest.rs:4:5: 4:6 error: cannot borrow immutable borrowed content `*h` as mutable
hashtest.rs:4 h.insert("foo", "bar");
^