use std::collections::hash_map::HashMap; struct MyStruct { a: u64, b: u64, } struct Test { counter: u64, map: HashMap, } impl Test { pub fn new() -> Test { Test { counter: 0, map: HashMap::new(), } } pub fn add_if_not_yet_exists(&mut self, key: u64, a: u64, b: u64) { self.map.entry(key).or_insert(self.add(a, b)); } pub fn add(&mut self, a: u64, b: u64) -> MyStruct { self.counter += 1; MyStruct {a: a, b: b} } } fn main() { let mut test = Test::new(); test.add_if_not_yet_exists(1, 2, 3); } /* error[E0499]: cannot borrow `*self` as mutable more than once at a time --> src/bin/test.rs:22:39 | 22 | self.map.entry(key).or_insert(self.add(a, b)); | -------- ^^^^ - first borrow ends here | | | | | second mutable borrow occurs here | first mutable borrow occurs here error: aborting due to previous error */