What unsafe means

An `unsafe` block tells the compiler that you, the programmer, are vouching for memory safety. The compiler still checks types — you only opt out of borrow checking and a handful of other invariants.

For deeper background, see the canonical Rust learning roadmap for the broader context behind this section.

Raw pointers

`*const T` and `*mut T` are raw pointers. They can be null, can dangle, and don't follow the borrow checker's rules. Dereferencing one requires unsafe.

Calling C

`extern "C" { fn foo(...) -> ...; }` declares a function from a C library. Combined with `#[link(name = "foo")]` you can call any C ABI library directly.

Writing safe abstractions

The most valuable use of unsafe is to wrap an unsafe operation in a safe API. The standard library is full of examples — Vec, Box, and the synchronization primitives all use unsafe internally.