title: Is it possible to have a binary heap containing different structs in Rust?
body: <p>I'm working on an event-driven particle simulation. The code below defines the struct Event and implements the equality traits that are needed for a binary heap. This code is working but the object event built by the second constructor (new_event) has redundant member variables. I want to have a binary heap which works with two different event structs in order to avoid this redundancy and improve my code efficiency which is crucial for my project.
  Can I achieve this using traits?</p>
  <pre><code>pub struct Event
  {
      pub time: f64,
      pub event_type: EventType,
      pub particle_index1: usize,
      pub particle_index2: usize,
      pub particle_count1: usize,
      pub particle_count2: usize
  }
  
  impl Event
  {
      pub fn new_collision(time: f64, particle_index1: usize, particle_index2: usize, 
          particle_count1: usize, particle_count2: usize) -&gt; Self
      {
  
          Self {
              time,
              particle_index1,
              particle_index2,
              event_type: EventType::EventCollision,
              particle_count1,
              particle_count2
          }
      }
  
      pub fn new_event(time: f64, event_type: EventType, particle_index1: usize, particle_count1: 
          usize) -&gt; Self
      {
          Self {
              time,
              particle_index1,
              particle_index2: 0, //REDUNDANT
              event_type,
              particle_count1,
              particle_count2: 0  //REDUNDANT
          }
      }
  }
  
  impl PartialEq for Event
  {
      fn eq(&amp;self, other: &amp;Self) -&gt; bool
      {
          self.time == other.time
      }
  }
  
  impl Eq for Event{}
  
  impl PartialOrd for Event
  {
      fn partial_cmp(&amp;self, other: &amp;Self) -&gt; Option&lt;Ordering&gt;
      {
          other.time.partial_cmp(&amp;self.time) //reverse order
      }
  }
  
  impl Ord for Event
  {
      fn cmp(&amp;self, other: &amp;Self) -&gt; Ordering
      {
          self.partial_cmp(other).unwrap()
      }
  }
  </code></pre>