There is any common pattern to implement something like this in Rust?
The error is
cannot borrow `sprite` as mutable because it is also borrowed as immutable I understand the problem but have no idea how to implement something like this in Rust.
struct Sprite { position: i32, } impl Sprite { pub fn left(&mut self) { self.position += 1; } } struct Game<'g> { sprite: &'g Sprite, } impl<'g> Game<'g> { pub fn new(sprite: &Sprite) -> Game { Game { sprite: sprite } } } fn main() { let mut sprite = Sprite { position: 3 }; let game = Game::new(&sprite); sprite.left(); } The code is also available on the playground.