I have this C code:
typedef void (*f_t)(int a);
struct Foo {
f_t f;
};
extern void f(struct Foo *);
bindgen generates the following Rust code (I have removed unimportant details):
#[repr(C)]
#[derive(Copy, Clone)]
#[derive(Debug)]
pub struct Foo {
pub f: ::std::option::Option<extern "C" fn(a: ::std::os::raw::c_int)>,
}
I do not understand why Option
is here. Obviously that Rust enum
and C pointer are not the same thing on the bit level, so how does the Rust compiler handle this?
When I call the C f
function and pass a pointer to a Rust struct Foo
, does the compiler convert Foo_rust
to Foo_C
and then only pass a pointer to Foo_C
to f
?