I'm still a bit new to Rust, so I'm not quite sure how to restructure my code properly to make what I'm trying to do possible. Here's a link to an MCVE of the code I'm running.
Essentially what I'm trying to do is iterate through a vector of entities and get an action from each of them. I don't need a mutable borrow for that part specifically, but I do need to pass a mutable reference to self
into a method later in the function to perform the action that was returned.
Here's the exact error message I'm getting:
error[E0502]: cannot borrow `*self` as immutable because it is also borrowed as mutable
--> src/main.rs:16:72
|
16 | let action = self.entities[self.current_entity].get_action(self);
| ------------- ---------- ^^^^ immutable borrow occurs here
| | |
| | mutable borrow later used by call
| mutable borrow occurs here
error: aborting due to previous error
How should I structure my code so that what I'm trying to do is possible?