title: How does a repr(C) type handle Option?
body: <p>I have this C code:</p>
  
  <pre class="lang-c prettyprint-override"><code>typedef void (*f_t)(int a);
  
  struct Foo {
          f_t f;
  };
  
  extern void f(struct Foo *);
  </code></pre>
  
  <p><a href="https://github.com/Yamakaky/rust-bindgen" rel="nofollow">bindgen</a> generates the following Rust code (I have removed unimportant details):</p>
  
  <pre><code>#[repr(C)]
  #[derive(Copy, Clone)]
  #[derive(Debug)]
  pub struct Foo {
      pub f: ::std::option::Option&lt;extern "C" fn(a: ::std::os::raw::c_int)&gt;,
  }
  </code></pre>
  
  <p>I do not understand why <code>Option</code> is here. Obviously that Rust <code>enum</code> and C pointer are not the same thing on the bit level, so how does the Rust compiler handle this?</p>
  
  <p>When I call the C <code>f</code> function and pass a pointer to a Rust struct <code>Foo</code>, does the compiler convert <code>Foo_rust</code> to <code>Foo_C</code> and then only pass a pointer to <code>Foo_C</code> to <code>f</code>?</p>