title: How to typecast and inherit Rust structs?
body: <p><strong>Note:</strong> This was asked about a pre-1.0 version of Rust, involving a feature which has since been withdrawn from the language.</p>
  <hr />
  <p>I am using the experimental feature <code>feature(struct_inherit)</code>.</p>
  <p>I have the <code>LocalPlayer</code> and <code>NetPlayer</code> structs and they both implement the <code>Inputable</code> trait as well as inherit the <code>player_num</code> field from the virtual struct <code>Player</code>. Depending on how a game starts, <code>player_2</code> in my program can either be a <code>LocalPlayer</code> or <code>NetPlayer</code>. Depending on which one, the way that the <code>Inputable</code> trait is implemented changes.</p>
  <p>The compiler won't let me dynamically assign <code>player_2</code> a type depending on whether it's a <code>NetPlayer</code> or <code>LocalPlayer</code>. It complains:</p>
  <blockquote>
  <p>error: mismatched types: expected <code>~player::LocalPlayer</code> but found <code>~player::NetPlayer</code> (expected struct player::LocalPlayer but found struct player::NetPlayer)</p>
  </blockquote>
  <p>It also won't let me typecast <code>NetPlayer</code> or <code>LocalPlayer</code> pointers to a <code>Player</code> pointer. It claims they aren't scalable.</p>
  <p>The code sample in question is as follows:</p>
  <pre class="lang-rust prettyprint-override"><code>let player1 = box player::LocalPlayer::new(0);
  let player2;
  if local {
      player2 = box player::LocalPlayer::new(1);
  } else if hosting {
      player2 = box player::NetPlayer::new(1);
      player2.host();
  } else {
      player2 = box player::NetPlayer::new(1);
      player2.connect();
  }
  /* ... Omitted Code ... */
  let input = player2.get_input(); // Trait function
  </code></pre>
  <p>The struct implementations are as follows:</p>
  <pre class="lang-rust prettyprint-override"><code>pub virtual struct Player {
      player_num: uint
  }
  pub struct LocalPlayer: Player;
  pub struct NetPlayer: Player;
  </code></pre>