title: trait cannot be made into an object
body: <p>I'm working on a ray tracer and want to model all hitable objects to provide a common interface.</p>
  
  <p>I implemented a trait named Object which all hitable objects implement. I created a struct called Intersection which contains an f32 value and a reference to struct that implements Object trait.</p>
  
  <p>The code:</p>
  
  <pre class="lang-rust prettyprint-override"><code>use std::sync::atomic::{AtomicUsize, Ordering};
  use super::ray::Ray;
  use std::ops::{Index};
  
  static mut ID : AtomicUsize = AtomicUsize::new(0);
  
  pub trait Object {
      fn intersection&lt;'a, T: Object&gt;(&amp;self, ray: &amp;Ray) -&gt; Intersections&lt;'a, T&gt;;
      fn get_uid() -&gt; usize {
          unsafe {
              ID.fetch_add(1, Ordering::SeqCst);
              ID.load(Ordering::SeqCst)
          }
      }
  }
  
  pub struct Intersection&lt;'a, T: Object&gt;{
      pub t: f32,
      pub obj: &amp;'a T,
  }
  
  impl&lt;'a, T: Object&gt; Intersection&lt;'a, T&gt; {
      pub fn new(t: f32, obj: &amp;'a Object) -&gt; Intersection&lt;'a, T&gt; {
          Self {t, obj}
      }
  }
  
  pub struct Intersections&lt;'a, T: Object&gt; {
      pub hits: Vec&lt;Intersection&lt;'a, T&gt;&gt;,
  }
  
  impl&lt;'a, T: Object&gt; Intersections&lt;'a, T&gt; {
      pub fn new() -&gt; Self {
          Self {
              hits: Vec::new(),
          }
      }
      pub fn push(&amp;self, hit: Intersection&lt;'a, T&gt;) {
          self.hits.push(hit);
      }
      pub fn len(&amp;self) -&gt; usize {
          self.hits.len()
      }
  }
  </code></pre>
  
  <p>The error message is as follows:</p>
  
  <pre><code>error[E0038]: the trait `object::Object` cannot be made into an object
    --&gt; src/object.rs:23:5
     |
  23 |     pub fn new(t: f32, obj: &amp;'a Object) -&gt; Intersection&lt;'a, T&gt; {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `object::Object` cannot be made into an object
     |
     = note: method `intersection` has generic type parameters
     = note: method `get_uid` has no receiver
  </code></pre>
  
  <p>Since I'm storing a reference in the Intersection, I supposed it doesn't have to deal with the actual size of the struct.</p>