Hi
Trying to Create a hashmap of hashmap of the form
// 01: {Start:xx, End:xx, Time:xx}, 02: {Start:xx, End:xx,Time:xx}
let file = File::open(&filename)?;
let mut map1:HashMap<String,HashMap<String,String>> =
HashMap::with_capacity(100);
let mut reader = BufReader::new(file);
let mut line = String::new();
loop {
match reader.read_line(&mut line) {
Ok(bytes_read) => {
if bytes_read == 0 {
return Ok(());
}
if const_identity.starts_with("A") {
//Inner hashmap
let mut map2:HashMap<String,String> = HashMap::with_capacity(10);
map2.insert("thread".to_string(),thread_num.to_string());
map2.insert("start".to_string(),time_start.to_string() );
map1.insert(thread_num.to_string(),map2);
} else if const_identity.starts_with("B") {
// Error
let map2:&HashMap<String, String>
= &mut map1.get_mut(&thread_num.to_string() ).unwrap();
map2.insert(count.to_string(),time_count.to_string());
}
line.clear();
}
The compiler tells me
map2.insert(count.to_string(),time_count.to_string());
cannot borrow *map2
as mutable, as it is behind a &
reference
map2
is a &
reference, so the data it refers to cannot be borrowed as mutable
How do I update the inner hashmap ?