This article is more than 1 year old
Rust 2021 edition to arrive in October with 'more consistent panic' and other new features
Also: Why Rust in Android will use the Soong build system, not Cargo
The Rust 2021 Edition Working Group has scheduled the new version for release in October, with what it says are small changes that amount to a significant improvement.
This is the "third edition of the Rust language," said Mara Bos, founder and CTO of Fusion Engineering and a Rust Library Team member. The previous editions are Rust 2015 and Rust 2018.
"Edition" is a special concept in Rust, as explained here. Updates to Rust ship frequently, but the special feature of an edition is that it can include incompatible changes. A crate (Rust term for a library) has to be explicitly configured to support an edition so older code will continue to work correctly. The Rust compiler can link crates of any edition.
The 2021 edition is not intended to be a big update, as explained in the most recent RFC (Request for Comments). "The Rust 2018 Edition was described in RFC 2052 as being a 'rallying point'... in contrast, the 2021 Edition is intentionally a 'low key' event, which is focused exclusively on introducing some migrations, idiom lints, and other bits of work that have been underway for some time," it says.
Bos said the latest post is the "final list of edition changes." One of the conditions for inclusion was that they were far enough along that the team is confident of their completion in time.
The first new feature that Rust 2021 will have is a new prelude that includes TryInto, TryFrom and FromIterator from the Rust standard library. The feature resolver 2 introduced in Rust 1.51 (March 2021), which is smarter about resolving dependencies, is the default in Rust 2021. Array iteration works as you would expect (until Rust 1.53 code can only iterate over references to arrays, not over arrays directly), despite what Bos called "a small hack to avoid breakage" in older editions. Closures will "only capture the fields that they use", a change which has waited for the new edition for compatibility reasons.
Rust 2021 also has some changes to the panic!() macro, used to signal an unrecoverable error. This macro accepts an argument that normally describes the error, such as panic!("Divide by zero error");. The macro used to accept any type when invoked with an argument, which could cause problems for outputting the error. In Rust 2021 it will only accept a string, and coders who wish to panic in the old way will need to use panic_any().
Rust adoption is increasing. Microsoft recently released Rust 0.9 for Windows with "access to the entire Windows API surface." Facebook has joined the Rust Foundation and promised to make it "a mainstream language of choice for systems programming and beyond."
Rust in Android: an update
Google is integrating Rust into the Android Open Source Project and has recently given an update on progress.
There are some complications with Rust in Android, particularly around the build system. Normally Rust uses Cargo, its own build system and package manager, but for building Android Google will use Soong, which will call the rustc compiler directly.
It is a trade-off. The Android team said that "Cargo was not designed for integration into existing build systems" but that avoiding it "introduces several challenges and influences many other build system decisions because Cargo usage is so deeply ingrained in the Rust crate ecosystem." The team said: "In the near future, we plan to add documentation to source.android.com on how to define and use Rust modules in Soong." ®