I'm writing a program to calculate the frequency of word occurrence. This is a segment of my code.
// hm is a HashMap<&str, u32>
if let Some(val) = hm.get_mut(tt) {
*val += 1u32;
} else {
hm.insert(tt.clone(), 1u32);
}
And I got...
error: cannot borrow `hm` as mutable more than once at a time [E0499]
hm.insert(tt.clone(), 1u32);
^~
note: first mutable borrow occurs here
if let Some(val) = hm.get_mut(tt) {
^~
note: first borrow ends here
}
^
help: run `rustc --explain E0499` to see a detailed explanation
I can bypass this by moving hm.insert()
out of else
scope but it's kind of "un-programmatic" way... I tried using match
but the same error (would obviously) happened.
How can I fix this?