Hashmap in a struct

i use a hashmap to store data in a struct, like this:

struct A {
}



struct B {
members: HashMap<u32, A>
}

impl B {

/// do something by key
fn fn_a(&mut self, key: u32) {
  let value = self.members.get_mut(&key).unwrap(); // 

  /// do something

  self.fn_b(); // no problem

 // depending on value, need to call fn_c to modify other data.
  self.fn_c(); // problem arise: E0499/E0502

}

fn fn_b(&self) {
}

fn fn_c(&mut self) {

}



}

when calling fn_c in fn_a, the E0499: brrow as mutable more than once at a time comes out.

My problem is not why E0499 comes out, but how to deal with problem in this case:

in a function, i have to modify data stored in a map, but also, i need to call another function to modify other data depend on this data, but in a E0499 restriction, how to do this.

Your minimized example compiles, so it's hard to give specific advice, but the scenario sounds like an interprocedural conflict more generally. The post covers some workarounds.

1 Like

thanks for your reply.
figured out how to deal with this case.