October 2018
Beginner
180 pages
4h 48m
English
When we use a variable name in a pattern, it matches any value and the matched value is stored in the variable. That means that if we were to try this:
let x = 5;let source6 = DemoStruct {id: 7, name: String::from("oops"), probability: 0.26};if let DemoStruct { id: x, name: _, probability: _ } = source6 { println!("The pattern matched, x is {}", x);}
We do not get a pattern that compares the source6.id value to the value of x (five in this case), we don't get what we expect.
Instead, we get an error saying that the pattern is irrefutable:

Read now
Unlock full access