New Features In Rust Include Generic Associated Types (GATs) After Six-Year Wait
An earlier post pointed out that “There have been a good amount of changes that have had to have been made to the compiler to get GATs to work,” noting that the request-for-comments for this feature was first opened in 2016.
And Rust’s types team also created a blog post with more detail:
Note that this is really just rounding out the places where you can put generics: for example, you can already have generics on freestanding type aliases and on functions in traits. Now you can just have generics on type aliases in traits (which we just call associated types)….
In general, GATs provide a foundational basis for a vast range of patterns and APIs. If you really want to get a feel for how many projects have been blocked on GATs being stable, go scroll through either the tracking issue: you will find numerous issues from other projects linking to those threads over the years saying something along the lines of “we want the API to look like X, but for that we need GATs” (or see this comment that has some of these put together already). If you’re interested in how GATs enable a library to do zero-copy parsing, resulting in nearly a ten-fold performance increase, you might be interested in checking out a blog post on it by Niko Matsakis.
All in all, even if you won’t need to use GATs directly, it’s very possible that the libraries you use will use GATs either internally or publically for ergonomics, performance, or just because that’s the only way the implementation works…. [A]ll the various people involved in getting this stabilization to happen deserve the utmost thanks. As said before, it’s been 6.5 years coming and it couldn’t have happened without everyone’s support and dedication.
Rust 1.65.0 also contains let-else statements — a new kind of let statement “with a refutable pattern and a diverging else block that executes when that pattern doesn’t match,” according to the release announcement.
And it highlights another new feature:
Plain block expressions can now be labeled as a break target, terminating that block early. This may sound a little like a goto statement, but it’s not an arbitrary jump, only from within a block to its end. This was already possible with loop blocks, and you may have seen people write loops that always execute only once, just to get a labeled break.
Now there’s a language feature specifically for that! Labeled break may also include an expression value, just as with loops, letting a multi-statement block have an early “return” value.
Read more of this story at Slashdot.