title: How can I do a mutable borrow after an immutable borrow?
body: <p>The code</p>
  <pre><code>fn play(&amp;self, game: &amp;mut crate::game::Game) {
      let player_in_turn: &amp;Player = game.get_player_in_turn();
      match player_in_turn.player_kind {
          PlayerKind::AI =&gt; {
              player_in_turn.do_random_move(&amp;mut game);
          }
          _ =&gt; {
              panic!(&quot;not implemented yet&quot;);
          }
      }
      game.status = Status::ExitGame;
  }
  </code></pre>
  <p>Where <code>get_player_in_turn</code> is</p>
  <pre><code>pub fn get_player_in_turn(&amp;self) -&gt; &amp;Player {
      match self.status {
          Status::InGame(ig_status) =&gt; match ig_status {
              InGameStatus::PlayFirst =&gt; {
                  if self.player_a.play_order == PlayOrder::First {
                      &amp;self.player_a
                  } else {
                      &amp;self.player_b
                  }
              }
              InGameStatus::PlaySecond =&gt; {
                  if self.player_a.play_order == PlayOrder::Second {
                      &amp;self.player_a
                  } else {
                      &amp;self.player_b
                  }
              }
          },
          _ =&gt; {
              panic!(&quot;get_player_in_turn called when not in a in-game status&quot;);
          }
      }
  }
  </code></pre>
  <p>The compiler is telling me</p>
  <pre><code>error[E0502]: cannot borrow `game` as mutable because it is also borrowed as immutable
    --&gt; src\game\status\in_game_status.rs:28:47
     |
  25 |         let player_in_turn: &amp;Player = game.get_player_in_turn();
     |                                       ------------------------- immutable borrow occurs here
  ...
  28 |                 player_in_turn.do_random_move(&amp;mut game);
     |                                -------------- ^^^^^^^^^ mutable borrow occurs here
     |                                |
     |                                immutable borrow later used by call
  </code></pre>
  <p>Usually I am able to understand the what and the why of compilers erros</p>
  <h2>I understand this</h2>
  <ol>
  <li><p><code>let player_in_turn: &amp;Player = game.get_player_in_turn(); </code> : I keep from <code>game</code> a ref to the current player; so I get an immutable ref of kind &amp;Player</p>
  <p>Here the <code>game</code> variable is immutably borrowed because of fn signature <code>get_player_in_turn(&amp;self)</code>. That's right, I do not want allow modifications to game in the get_player_in_turn, but also I need a ref because I need the player in turn, not a copy, or what else</p>
  </li>
  <li><p><code>player_in_turn.do_random_move(&amp;mut game);</code> : The instance of Player now alters the game itself doing its move</p>
  <p>And here <code>game</code> should be passed as mutable because it's the goal of <code>do_random_move</code></p>
  </li>
  </ol>
  <h2>Question</h2>
  <p>I can understand the <em>why</em> of this but not how can I workaround</p>