This makes the code a little shorter, makes the code more DRY (because there’s no need to re-state the argument names), and encourages more usage of match. Haskell syntax allows something similar. Are match-only functions common enough in Rust to justify adding such syntax sugar?
I initially thought this would really help with one module I’d written, but taking a quick look over it I realized I’ve used a pattern that doesn’t quite work with this: matching on a dereferenced &mut self parameter. Currently that looks like (assuming Bar and Baz are enum variants used in the current module):
which, while it drops a level of indentation, forces adding the &mut back onto the start of each pattern; that makes scanning the patterns seem much harder to me. It would be amazing if there were some way to enhance this sugar to make this pattern work nicely as well.
Also, as mentioned in the linked issue, something similar for closures would be wonderful. I have a lot of cases where I .map a vector of enums so being able to skip the named closure argument there would really simplify the code.
FWIW, I plan to propose (or would support a proposal...) to "autoderef" on match, at least at the outermost level (though I'd prefer to do it at all levels). In that case, match self and match *self would be equivalent.
That would be really useful, especially if combined with something like this feature
I presume doing it at all levels would include doing it inside tuples (needed for the multi-argument version of this sugar), I also have a lot of methods implementing binary operators so they're all like