21.4 Plain Variable Assignment as a Pattern
Every let x = something;
statement in Rust is technically a pattern match where x
is the pattern. This can be more elaborate:
fn main() { let (width, height) = (20, 10); println!("Width = {}, Height = {}", width, height); }
Here, (width, height)
is an irrefutable tuple pattern that binds each element to a separate variable. A mismatch is impossible: (20, 10)
always matches (width, height)
. Attempting a refutable pattern—something that might fail—would be invalid in a regular let
statement.