liveBook · Manning

Static mut

static mut is a Rust declaration for mutable statically allocated storage with a program-wide lifetime, whose access requires unsafe handling.

How 2 Manning books explain it

Rust in Action: Systems programming concepts and techniques

static mut declares a mutable Rust static variable with a program-wide lifetime and mutable access requiring unsafe handling.

How it is used
Deploys mutable global state for flags, error propagation, and communication with operating-system mechanisms such as signal handlers.
How deep it goes
Explains declaration and unsafe reads and writes through complete toy programs, but stops short of detailed concurrency guarantees.
Examples
Uses shutdown flags, random Boolean updates, global error codes, file operations, and panic output as concrete demonstrations.
What you can do after
Apply mutable statics in small Rust programs that use global flags or error state, while identifying why unsafe access demands caution.

Read how Rust in Action: Systems programming concepts and techniques explains static mut →

Learn Rust in a Month of Lunches

A static mut is a Rust static value that can be directly modified, but accessing it requires unsafe code because unsynchronized access can violate aliasing rules or cause data races.

How it is used
Introduces mutable statics as an entry point to unsafe Rust and contrasts them with safer ways to modify shared state.
How deep it goes
Demonstrates declaration, compiler rejection, unsafe access, and nondeterministic threaded results, but does not develop a safe replacement.
Examples
Uses NUMBER, a ten-thread increment test, and a thousand-thread stress test with inconsistent totals.
What you can do after
Diagnose why mutable-static access requires unsafe blocks and why unsynchronized increments can produce undefined behavior.

Read how Learn Rust in a Month of Lunches explains static mut →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.