3 ms·
> I feel some of rust’s syntactic choices are confusing. For instance: > let x = 2 > Introduces a new name and binds it to the value 2 while > if let Some(x)
by beltsazar 4y ago
> I feel some of rust’s syntactic choices are confusing. For instance:
> let x = 2
> Introduces a new name and binds it to the value 2 while
> if let Some(x) = y
> Is a shorthand for pattern matching.
It won't be as confusing once you realize that both do the same thing: variable binding. The difference is that the former is an irrefutable binding, whereas the latter is a refutable binding.
Suppose that we have:
struct Foo(i32);
A few more examples of irrefutable binding:
1. As a local variable:
let Foo(x) = Foo(42);
2. As a function parameter:
fn bar(Foo(x): Foo) {}