title: Multiple borrow in Rust
body: <p>There is any common pattern to implement something like this in Rust? </p>
  
  <p>The error is </p>
  
  <pre class="lang-none prettyprint-override"><code>cannot borrow `sprite` as mutable because it is also borrowed as immutable
  </code></pre>
  
  <p>I understand the problem but have no idea how to implement something like this in Rust.</p>
  
  <pre><code>struct Sprite {
      position: i32,
  }
  
  impl Sprite {
      pub fn left(&amp;mut self) {
          self.position += 1;
      }
  }
  
  struct Game&lt;'g&gt; {
      sprite: &amp;'g Sprite,
  }
  
  impl&lt;'g&gt; Game&lt;'g&gt; {
      pub fn new(sprite: &amp;Sprite) -&gt; Game {
          Game { sprite: sprite }
      }
  }
  
  fn main() {
      let mut sprite = Sprite { position: 3 };
  
      let game = Game::new(&amp;sprite);
  
      sprite.left();
  }
  </code></pre>
  
  <p>The code is also available on the <a href="https://play.rust-lang.org/?gist=642a6dcb773d6fbcd859821912db49c3&amp;version=stable&amp;backtrace=0" rel="nofollow noreferrer">playground</a>.</p>