5、Appendix E - Editions(the book)
edition guide official website
In Chapter 1, you saw that some metadata about edition was added cargo new
to the file. Cargo.toml
This appendix discusses what that means!
The Rust language and compiler have a six-week release cycle, which means users are constantly getting new features. Other programming languages release larger changes less frequently; Rust releases smaller updates more frequently. After a while, all these small changes keep adding up. But from version to version, looking back and saying, "Wow, a lot has changed in Rust between Rust 1.10 and Rust 1.31!"
Every two or three years, the Rust team generates a new one Rust edition
. Each release consolidates committed features into a clean package and comes with fully updated documentation and tools. New editions are usually released during a six-week release process.
Edition
Serve different purposes for different people:
- For active Rust users, the new edition consolidates incremental changes into one easy-to-understand package.
- For non-users, the new edition marks some major improvements that have been implemented, which might make Rust worth a second look.
- For those developing Rust, the new edition provides a meeting point for the entire project.
At the time of writing, there are three Rust versions available: Rust 2015, Rust 2018, and Rust 2021. This book is written using Rust 2021 idioms.
edition
The key is Cargo.toml
instructing the compiler which one it should use for your code edition
. If the key does not exist, Rust uses 2015 as the value for backward compatibility reasons edition
.
Each project can choose edition
a version other than the 2015 default. Edition
Can contain incompatible changes, such as including new keywords that conflict with identifiers in the code. However, unless you opt-in to these changes, your code will continue to compile even if you upgrade the version of Rust compiler you use.
All Rust compiler versions support any that existed before that compiler was released edition
, and they can link together any supported version. Version changes only affect how the compiler initially parses the code. So if you're using Rust 2015, and one of your dependencies uses Rust 2018, your project will compile and be able to use that dependency. The opposite situation, where your project uses Rust 2018 and your dependencies use Rust 2015, will work as well.
To be clear: most features will editions
be available on all . edition
Developers using any Rust will continue to see improvements as new stable releases are released . However, in some cases, mainly when new keywords are added, some new features may only editions
be available later. If you want to take advantage of these features, you need to switch editions
.
For more details, the Edition Guide is a editions
complete book on , which enumerates editions
the differences and explains how to cargo fix
upgrade your code to the new one by automating it edition
.