Announcing the ffi_helpers crate

I’ve just released the ffi_helpers crate :tada:

This is the open-source version of something we’ve used internally at work for integrating our Rust modules into the main GUI application via a C API. We found it to make things quite ergonomic (the Task API makes executing background Rust tasks from C particularly nice!) and thought others could make use of it too.

This crate is designed to make writing FFI code a lot easier and safer, letting you

  • Provide a single interface for exposing fallible operations to C using something akin to a private thread-local errno
  • Handle null pointers, return early with an “obviously invalid” value via the Nullable trait so callers know to inspect the most recent error for more detains
  • Make your application exception safe by preventing panics from reaching the FFI barrier
  • Spawn a task onto a background thread and let your C code poll it for completion, cancel it early, or return the result (or error) once the task is done

You probably want to inspect the API docs for more information on how you can use the ffi_helpers crate to make your FFI code safer.