-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow an optional vert at the beginning of a match #36361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@mdinger Syntax addition requires a RFC. I like it more than: #![allow(dead_code)]
use E::*;
enum E {
A,
B,
C,
D,
}
fn main() {
match A {
A
| B
| C
| D => (),
}
// or
match A {
A
| B
| C
| D => (),
}
} But I'm not sure about implementation's complexity. |
I would like to point out two aspects (please correct me if I am wrong):
#![allow(dead_code)]
use E::*;
enum E {
A,
B,
C,
D,
}
fn main() {
match A {
| A
| B => println!("Give me A | B!"),
| C
| D => println!("Why am I here?"),
}
} Please let me know if I misunderstood the proposal. Could you please provide an example which better illustrates the benefits of this syntax? |
@Victor-Savu enum E { A, B, C }
fn main() {
use E::*;
let value = A;
match value {
A | B => {},
C => {}
}
} After syntax changes could be rewritten like: enum E { A, B, C }
fn main() {
use E::*;
let value = A;
match value {
| A
| B => {},
C => {}
}
} |
Please leave further comments in rust-lang/rfcs#1745 |
See how in the following, all the
|
bars are mostly aligned except the last one:I'd propose it be allowed at the beginning of the pattern as well enabling something like this:
This appears to be the official style for F# matches and it has grown on me a lot. It highlights the matches and doesn't require as much deeper nesting. After getting used to the F# style, the inability to do this is rust seems a bit limiting.
I'm not sure if this issue should be in this repo or not but just direct me if I have to move it.
The text was updated successfully, but these errors were encountered: