use std::collections::HashMap;
use std::collections::hash_map::Entry::*;
struct A {
map: HashMap<String, String>,
i: i32
}
impl A {
fn test(&mut self) {
match self.map.get("abc") {
None => {},
Some(x) => self.trigger(&x)
}
}
fn trigger(&mut self, x: &str) {
self.i += 1;
}
}
The code doesn't work because self.trigger
borrows self
mutably, while self.map.get
is keeping an immutable borrow of self
in scope.
Is there any way to make it work, given that I can make sure in the trigger
I don't modify self.map
?
I cannot make trigger
borrow self
immutably, as in Can I borrow self immutably for self.callbacks: Vec<Box<FnMut>>?
I'm using rustc 1.19.0-nightly.