Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 753 Bytes

declaring_a_constant.md

File metadata and controls

18 lines (14 loc) · 753 Bytes

Declaring a Constant

Rust has two different types of constants which can be declared in any scope including global. Both require explicit type annotation:

  • const: An unchangeable value (the common case).
  • static: A possibly mutable variable with 'static lifetime. The static lifetime is inferred and does not have to be specified. Accessing or modifying a mutable static variable is unsafe.
// Globals are declared outside all other scopes.
static LANGUAGE: &str = "Rust";
const THRESHOLD: i32 = 10;

References