let — variable binding (can be mutable). const — compile-time constant (always immutable).
let:
let mut for mutable variables.1let x = 5; // Immutable2let mut y = 10; // Mutable3y += 5; // OK45let (name, age) = ("Alice", 30); // Destructuring6let [a, b, ..] = [1, 2, 3, 4]; // Slice pattern
const:
const mut).1const MAX_BUFFER: usize = 4096;2const VERSION: (u8, u8, u8) = (1, 0, 0);3const COLORS: [u8; 3] = [255, 128, 0];45const fn add(a: i32, b: i32) -> i32 { a + b }6const RESULT: i32 = add(10, 20); // 30
When to use:
const for configuration values and compile-time constants.let for general variables and runtime computations.static for global values with fixed memory addresses.Common mistakes:
const — compiler requires it.const at runtime — must be a constant expression.const and static — they have different semantics.