Description
Relatively new to Rust, and reading through the Nomicon to make sure I build a new FFI module safely. I noticed one omission in https://github.com/rust-lang-nursery/nomicon/blob/master/src/other-reprs.md.
#13 added language to call out that Option<&T>
is FFI-safe as long as *const T
is FFI-safe. Based on rust-lang/rust#40913, it seems that the preferred way of expressing nullable function pointers (returned via FFI) is using Option<fn>
(or I guess Option<extern "C" fn>
since function pointers set by C code are presumably also C-ABI).
If my understanding is correct, shall we add this to the Nomicon? I'm happy to send a PR if that's desired.
Also, are Option<&T>
and Option<extern "C" fn>
an exhaustive list of repr(C)
FFI-safe enums with fields, or are there other exceptions to document as well?