So I am learning Rust by writing a NES emulator. I have implemented a Bus trait which allows all my structs to talk to other structs via read and write methods. Everything was going great until I added a step function which requires a mut ref to self and then will call the step functions of the other parts (cpu, ppu, etc.)
// step one cycle - for debugging
pub fn step(&mut self) {
self.cpu.step(&mut self, 1);
^^^^
|
cannot reborrow mutably
try removing `&mut` here
I get a "cannot reborrow mutably try removing '&mut' here" but these objects need to be mutable, when the cpu steps it will change its state. So will the ppu and any other objects.
Here is a link to the file nes
I implemented Bus for Nes and have the proper lifetimes, but how does one group calls to several objects while passing itself mutably?
Should I somehow redesign so the ram and Bus implementation are included with the cpu?
I am using the 1.21 Rust. I have no other errors anywhere else.