let — variable binding (can be mutable or immutable). const — compile-time constant (always immutable).
let:
let mut for mutable variables.1let x = 5; // Immutable2let mut y = 10; // Mutable3y = 20; // OK45// Destructuring6let (a, b) = (1, 2);7let Point { x, y } = point;
const:
const mut).1const MAX_POINTS: u32 = 100_000;2const GREETING: &str = "Hello, World!";3const ARRAY: [i32; 3] = [1, 2, 3];45// const can use const fn6const fn square(x: i32) -> i32 { x * x }7const RESULT: i32 = square(5); // 25
When to use:
const for configuration values, sizes, magic numbers.let for general-purpose variables and computations.let mut when values need to change.Common mistakes:
const — it's required by the compiler.const at runtime — it must be a constant expression.static thinking it's like const — they have different semantics.