liveBook · Manning

Static mut

Also called mutable static

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 →

Also covered in

What to know first

Related concepts

Questions about static mut

What is static mut?

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

Which Manning books explain static mut?

Rust in Action: Systems programming concepts and techniques and Learn Rust in a Month of Lunches.

What should I know before learning static mut?

Manning books that teach static mut usually introduce Arc first.

What is the difference between static mut and constant?

static mut is a Rust declaration for mutable statically allocated storage with a program-wide lifetime, whose access requires unsafe handling. A constant is a value or named binding treated as fixed rather than reassigned or modified during a computation, whether this is enforced by a language or followed by convention.

What is static mut a kind of?

Static mut is a kind of static field. A static field is a named variable associated with a class or program scope, rather than stored separately for each object instance.

What is static mut also called?

Static mut is also called mutable static.

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.