Unsafe Rust & FFI

Unsafe Rust and FFI are the parts of Rust where correctness depends on explicit human-maintained invariants around memory, aliasing, layout, ABI, initialization, and foreign code.

Concepts

Unsafe Rust

Raw Pointers

Dereferencing Raw Pointers

Extern statics

unsafe fn

Undefined Behavior

FFI with C

unsafe extern Blocks

Unions

MaybeUninit

Aliasing and Provenance

Miri

Soundness vs Safety

Patterns

Safe Abstractions over Unsafe Code

SAFETY Comments

FFI Wrapper Types

Pin projection

Antipatterns

The static mut Footgun and &raw

Transmute as a Shortcut

Sources