Hi,
I was jut remitting some code and in my attempt to rewrite one of the match blocks that looks something like this:
let a = 7u8;
let b = 5u8;
match (a,b) {
(5u8,_) | (7u8,_) | (_,0u8) => {println!(">> {}{}", a,b)},
(9u8,_) => {println!("{} {}", b,a)},
(_,_) => {println!("bla bla")},
}
into something like this:
let x = 5u8;
let y = 7u8;
let z = 9u8;
let a = 7u8;
let b = 5u8;
match (a,b) {
(x,_) | (y,_) | (_,0u8) => {println!(">> {}{}", a,b)},
(z,_) => {println!("{} {}", b,a)},
(_,_) => {println!("bla bla")},
}
I get:
Compiling playground v0.0.1 (/playground)
error[E0408]: variable `x` is not bound in all patterns
--> src/main.rs:11:13
|
11 | (x,_) | (y,_) | (_,0u8) => {println!(">> {}{}", a,b)},
| - ^^^^^ ^^^^^^^ pattern doesn't bind `x`
| | |
| | pattern doesn't bind `x`
| variable not in all patterns
...
My questions are:
- What is the problem ?
- How to resolve it ?
- Is there a better way to do this ?
thank you