21.4 Plain Variable Assignment as a Pattern
Every let x = something;
statement in Rust is effectively a pattern match. By default, x
itself is the pattern. However, you can make this more elaborate:
fn main() { let (width, height) = (20, 10); println!("Width = {}, Height = {}", width, height); }
Here, (width, height)
is an irrefutable tuple pattern. It always matches (20, 10)
. Any attempt to use a refutable pattern—something that might fail—would be disallowed in a plain let
.