title: How do I create a heterogeneous collection of objects?
body: <p>I want to use trait objects in a <code>Vec</code>. In C++ I could make a base class <code>Thing</code> from which is derived <code>Monster1</code> and <code>Monster2</code>. I could then create a <code>std::vector&lt;Thing*&gt;</code>. <code>Thing</code> objects must store some data e.g. <code>x : int, y : int</code>, but derived classes need to add more data.</p>
  
  <p>Currently I have something like</p>
  
  <pre><code>struct Level {
      // some stuff here
      pub things: Vec&lt;Box&lt;ThingTrait + 'static&gt;&gt;,
  }
  
  struct ThingRecord {
      x: i32,
      y: i32,
  }
  
  struct Monster1 {
      thing_record: ThingRecord,
      num_arrows: i32,
  }
  
  struct Monster2 {
      thing_record: ThingRecord,
      num_fireballs: i32,
  }
  </code></pre>
  
  <p>I define a <code>ThingTrait</code> with methods for <code>get_thing_record()</code>, <code>attack()</code>, <code>make_noise()</code> etc. and implement them for <code>Monster1</code> and <code>Monster2</code>.</p>