Conceptual
Login

Constants and Static Items in Rust

A constant is a fixed value baked into the code wherever it is used; a static is a single value that lives at one address for the whole life of the program. Use a constant for a register offset or a device ID, and a static when something genuinely must be one shared thing. Because a shared mutable static could be written by two threads at once, Rust will not let you change one without extra protection.

Questions this Concept answers

  • Why does Rust refuse to let safe code mutate a `static mut`?