title: Is it possible to use Fiddle to pass or return a struct to native code?
body: <p>I would like to use <a href="http://ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/Fiddle.html" rel="nofollow noreferrer">Fiddle</a> to access a native library compiled from Rust code. The C representation of the struct is very simple, it is just a pointer and a length:</p>
  
  <pre class="lang-C prettyprint-override"><code>typedef struct {
      char *data;
      size_t len;
  } my_thing_t;
  
  // Example function that somehow accepts a struct
  void accepts_a_struct(my_thing_t thing);
  
  // Example function that somehow returns a struct
  my_thing_t returns_a_struct(void);
  </code></pre>
  
  <p>However, all examples I can find accept or return pointers to structs, and not the structs themselves. I'd like to avoid the double indirection if at all possible.</p>
  
  <p>I've borrowed an example from the <a href="http://ruby-doc.org/stdlib-2.0.0/libdoc/fiddle/rdoc/Fiddle/Importer.html" rel="nofollow noreferrer"><code>Fiddle::Importer</code> documentation</a>. However, I do not see how to properly call the <code>extern</code> method with a structure instead of a pointer to a structure:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>require 'fiddle'
  require 'fiddle/import'
  
  module LibSum
    extend Fiddle::Importer
    dlload './libsum.so'
    extern 'double sum(double*, int)'
    extern 'double split(double)'
  end
  </code></pre>
  
  <p><strong>Note</strong></p>
  
  <p>Fiddle is <strong>not</strong> the same as the <a href="https://github.com/ffi/ffi" rel="nofollow noreferrer">FFI gem</a>. Fiddle is a component of the Ruby standard library, and is not provided as a separate gem. These related questions refer to the FFI gem, and not to Fiddle:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/8982393/155423">How to wrap function in Ruby FFI method that takes struct as argument?</a></li>
  <li><a href="https://stackoverflow.com/q/5372483/155423">How do I specify a struct as the return value of a function in RubyFFI?</a></li>
  </ul>