Skip to content
Select theme

Unsafe Rust and FFI

unsafe does not turn off the borrow checker, and it does not make the code wrong either. It grants five specific powers and asks you to keep the invariants yourself.

The FFI articles at the end are the reason most people get here: calling a C library, or being one.

Nothing published in this chapter yet — all 10 articles are still to come.

Coming up (10)
  • What is unsafe Rust, and when should you use it?five powers, and the invariants you now own
  • How to dereference a raw pointer*const T, *mut T, and the null check
  • How to call an unsafe function safelywrapping it so callers cannot get it wrong
  • How to implement an unsafe traitpromising something the compiler cannot check
  • What is undefined behaviour?the list, and why “it worked” means nothing
  • What is MaybeUninit for?the uninitialised memory problem
  • What is ManuallyDrop for?opting out of Drop, on purpose
  • How to call C code from Rustextern “C”, and the build script that links it
  • How to expose Rust functions to Cno_mangle, and the ABI you must design
  • How to use bindgen to generate bindingsfrom a C header to a Rust module