Unsafe Rust
unsafe doesn't mean memory-unsafe. It means you are responsible for maintaining the invariants the compiler can no longer verify.
The five unsafe superpowers:
- Dereference raw pointers
- Call unsafe functions or methods
- Access or modify mutable static variables
- Implement unsafe traits
- Access fields of
unions
Everything else — including the borrow checker — still applies inside unsafe blocks.
| Raw Pointers | *const T and *mut T — aliasing, alignment, validity |
| Unsafe Traits | Send, Sync, and custom unsafe contracts |
| FFI | extern "C", #[no_mangle], C interop patterns |
| Safety Invariants | How to document and enforce unsafe contracts |