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.
The more appropriate analogy is buying a super duper car with a navigation system that is less than stellar in getting you to some places, and using a 3rd party one instead.
You completely read my post right. I think it’s a good idea to move some lints from clippy to rustc, but as long as the lint exists, the world is ok in my opinion.
It allows to write code like this, without the catch-all “_”: