0.12Rust editions
One last piece of background before the real programming starts, and it answers a line you'll see in every project you create: what is an edition?
In lesson 0.3 we mentioned Rust's promise of stability: a new compiler version every six weeks, and code that compiles today keeps compiling on the new versions. That promise creates a dilemma. Languages learn from experience. Sometimes the designers want a new keyword, or want some old shorthand to mean something better, and changes like that would break existing code, which the promise forbids.
Editions are how Rust escapes the dilemma. Roughly every three years, the accumulated would-be-breaking changes are bundled into a named edition: so far 2015, 2018, 2021, and 2024. Each crate declares which edition it's written in, and the compiler holds every crate to the rules of its own edition. Code written under the old rules keeps compiling under the old rules, forever; new projects get the new rules from day one.
The declaration lives in your project's Cargo.toml file, and you'll never write it by hand; cargo new fills in the latest edition automatically:
edition = "2024"
The quietly remarkable part is that editions interoperate. Your 2024-edition program can depend on a crate last touched in 2017, written in the 2015 edition, and the two compile together without either author doing a thing. Ecosystems usually split when a language changes its rules (Python 2 versus Python 3 became a decade-long migration saga); Rust designed the split out of existence.
Key insight
Editions are not versions of the language. There's one Rust compiler, always current, and it understands every edition; an edition is just a per-crate setting for which dialect of surface rules that crate uses. Newer compiler versions bring new features to all editions. An edition boundary is only needed for the rare change that would alter the meaning of existing code.
What should you do about all this? Almost nothing, and that's the point:
Best practice
Use the latest edition for new projects, which cargo new already does. When a future edition arrives, Rust ships a migration tool (cargo fix --edition) that updates a project mechanically; until then, the edition line is one you read, not one you edit.
For advanced readers
What did the editions actually change? Mostly refinements you'll appreciate only after you know the language: 2018 reworked the module system, 2021 adjusted how closures capture variables, 2024 tightened some defaults around unsafe code, and new keywords were reserved along the way. Appendix B.1 will catalog the changes edition by edition; it will mean much more after chapter 13 than it would now.
If you've come from C++, this lesson is the punchline to a long setup: choosing and configuring a "language standard" there is a real chore. Compilers default to old standards for compatibility, every project must be told which of C++14/17/20/23 to use, and tutorials begin with a tour of build-settings menus. Rust's equivalent lesson is the one you just read: the setting exists, your tools already chose correctly, carry on.
And that's chapter 0: everything is installed, and you know what all the moving parts are for. In chapter 1, you stop reading about programs and start writing them: how Rust programs are structured, statement by statement, and what every line of "Hello, world!" actually means.