Variables & Basic Types in Rust
From the Rust cheat sheet ยท Variables & Types ยท verified Jul 2026
Variables & Basic Types
Declare variables with let, control mutability, and use primitive types.
rust
// Immutable by default
let x = 5;
let name = "Alice";
// Mutable
let mut count = 0;
count += 1;
// Type annotations
let age: u32 = 30;
let pi: f64 = 3.14;
let active: bool = true;
let letter: char = 'A';
// Constants
const MAX_SIZE: u32 = 100;๐ก Variables are immutable by default โ add mut only when you need to change the value
โก Shadowing lets you reuse a name with a different type โ unlike mut which keeps the type
๐ Use underscores in numeric literals for readability: 100_000 instead of 100000
๐ข Tuples destructure with let (x, y) = tup; arrays access with arr[0]
variablestypesmutability