In a recent good blog post Graydon discusses about various possible future improvements for programming languages. A section is about “Richer patterns”. In that section Graydon seems to miss the very refined pattern matching of Mathematica ( http://reference.wolfram.com/language/tutorial/PatternsAndTransformationRules.html ).
I’ve found that in my Rust code the parts where I use pattern matching are often more bug-free than other parts of code. So I’d like more care and love for pattern matching in Rust (in match, if-let and function signatures). About this there are some enhancement requests, RFCs and bug reports, but the progress is very slow.
Features like slice_patterns and their advanced version are experimental still after two years. Code like this compiles (and this is silly in a reliable language like Rust):
fn main() {
let x: u8 = 5;
match x {
0 ... 100 => (),
100 ... 255 => (), // 100 covered two times
_ => (), // required
}
}
The compiler sometimes compiles the Less/Equal/Greater variants not efficiently (compared to if/then).
This is redundant and I’d like a shorter syntax:
struct Foo(u32);
fn bar(Foo(x): Foo) {}
Like:
fn bar(Foo(x): _) {}
There are situations where you want “if let … && …”, there’s even a crate to help this (yes, you can use if let on a tuple and this solves some cases, but not where the second item of the tuple must be what you have extracted in the first part).
Something like the Scala unapply() method could be handy.