You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to match multiple patterns with guards to a single code block.
I was wondering if there is any reason why the following code does not compile?
let b = (3i,4i);
let g = 0i;
match b {
(2,_) | (_, 2) => println!("2 inside "), // this works fine
(2,_) if g > 0 => println!("First is 2 and some guards"), // also works fine
(2,_) if g > 0 | (_, 2) => println!("2 inside and some guards"), // this does not compile
....
}
Also have you considered allowing to use a general if condition syntax in matches, like this?
((2,_) && g > 0) || (_, 2) =>
Edit:
Also this does compile, but looks a bit ambiguous to what part of the pattern the guard applies to.
(2,_) | (_, 2) if g > 0 => println!("2 inside and some filters"),
The text was updated successfully, but these errors were encountered:
Hi,
I want to match multiple patterns with guards to a single code block.
I was wondering if there is any reason why the following code does not compile?
Also have you considered allowing to use a general if condition syntax in matches, like this?
Edit:
Also this does compile, but looks a bit ambiguous to what part of the pattern the guard applies to.
The text was updated successfully, but these errors were encountered: