Can we add an assist which can replace if matches!(..) with match expression like this?
From
if matches!(expr, pat) {
a
} else {
b
}
to
match expr {
pat => {
a
}
_ => {
b
}
}
My thought is to expand the matches! macro, but whitespaces and comments will be lost when expanding. For example:
if matches!(compute(arg1, /* comment*/ arg2), Enum::A | Enum::B) {
// ...
}
will become
match compute(arg1,arg2) {
Enum::A|Enum::B => {
// ...
}
_ => {
// ...
}
}
Is this acceptable? Or, are there any better solutions for this?
Can we add an assist which can replace
if matches!(..)withmatchexpression like this?From
to
My thought is to expand the
matches!macro, but whitespaces and comments will be lost when expanding. For example:will become
Is this acceptable? Or, are there any better solutions for this?