I want to get a mutable reference to something in a bigger struct because i use that reference a lot. The obvious solution is to create a variable for that. But sometimes I need to pass a mutable reference to the struct to a function, which causes 2 mutable references to be created. Which is not allowed in rust.
Heres an example:
let reference = &mut big_struct.thing.unwrap().get_mut(blahblah).unwrap();
let thing = my_function(&mut big_struct); // Not allowed
reference.modify(thing);
The solution to this is to only evaluate a variable only when its used. Like this:
let thing = my_function(&mut big_struct);
// &mut big_struct has expired and it can be referenced again
big_struct.thing.unwrap().get_mut(blahblah).unwrap().modify(thing);
But this causes the original problem to be an issue again. So is there a cleaner way to do this? Sorry if this doesn't make much sense.