title: Is there a way to determine the offsets of each of the trait methods in the VTable?
body: <p>I thought I could try <em>more or less</em> build a trait object from scratch without using the <code>impl</code> blocks. To elaborate:</p>
  
  <pre><code>trait SomeTrait {
      fn fn_1(&amp;self);
      fn fn_2(&amp;self, a: i64);
      fn fn_3(&amp;self, a: i64, b: i64);
  }
  
  struct TraitObject {
      data: *mut (),
      vtable: *mut (),
  }
  
  fn dtor(this: *mut ()) {
      // ...
  }
  
  fn imp_1(this: *mut ()) {
      // ...
  }
  
  fn imp_2(this: *mut (), a: i64) {
      // ...
  }
  
  fn imp_3(this: *mut (), a: i64, b: i64) {
      // ...
  }
  
  fn main() {
      let data = &amp;... as *mut (); // something to be the object
      let vtable = [dtor as *mut (),
                    8 as *mut (),
                    8 as *mut (),
                    imp_1 as *mut (),
                    imp_2 as *mut (),
                    imp_3 as *mut ()]; // ignore any errors in typecasting,
          //this is not what I am worried about getting right
  
      let to = TraitObject {
          data: data,
          vtable: vtable.as_ptr() as *mut (),
      };
      // again, ignore any typecast errors,
  
      let obj: &amp;SomeTrait = unsafe { mem::transmute(to) };
  
      // ...
  
      obj.fn_1();
      obj.fn_2(123);
      obj.fn_3(123, 456);
  }
  </code></pre>
  
  <p>From what I understand, the order in which the member functions appear in the trait definition is not always the same as the function pointers appear in the VTable. Is there a way to determine the offsets of each of the trait methods in the VTable?</p>