A few hours ago, @rustlang 1.56 was released! π¦
This version ships with the new edition: Rust 2021! πβ¨π
There's quite a few new features in the new version and edition:
1/17
Starting today, `cargo new` will use `edition = "2021"`. You can migrate your 2018 crates with `cargo fix --edition`.
These are all the edition changes:
1. `array.into_iter()` now iterates by value, instead of giving references.
(See for details.)
2/17
2. Closures in Rust 2021 will capture only the fields of an object you use, instead of the entire object. This should result in fewer fights with the borrow checker:
3/17
3. In Rust 2021, `$x:pat` in macro_rules now accepts patterns that include a `|`, making your macro rules easier to write:
4/17
4. Specifying `edition = "2021"` in your Cargo.toml implies `resolver = "2"`, when not explicitly given.
See the announcement of Rust 1.51 for details on Cargo's new resolver: blog.rust-lang.org/2021/03/25/Rusβ¦
5/17
5. In Rust 2021, you don't have to import the TryFrom, TryInto and FromIterator traits anymore. They are now part of the prelude, which is automatically imported into all your modules:
6/17
6. The panic!() (and assert) macros in Rust 2021 no longer behave inconsistently when given only one argument. This unblocks a feature that will be available in a few versions from now: implicit format arguments.
7/17
7. We reserved some syntax for identifiers and literals with prefixes in Rust 2021. This syntax doesn't mean anything *yet*, but reserving it means we can start giving meaning to it in the (near?) future:
8/17
And finally the last change that's part of the 2021 edition:
8. Some old syntax that's been deprecated for a while is completely removed in Rust 2021. This means we can use that syntax for something else in the future. (Maybe we can use `...` for variadic generics.)
9/17
Then let's continue with the changes in Rust 1.56 that are available in all editions:
1. Extend<(A, B)> for (Extend<A>, Extend<B>)
It allows splitting an iterator over tuples into separate collections, a bit like the opposite of .zip():
10/17
2. From<array> for BTreeMap, BTreeSet, HashMap, HashSet, VecDeque, LinkedList, and BinaryHeap.
You can now use e.g. BTreeMap::from(..) to make a collection with directly the contents you want:
11/17
3. You can now combine `@` bindings with regular pattern bindings. That means you can now give a name to an object _and give a name to some parts of it_ at the same time:
12/17
4. BufWriter::into_parts()
BufWriter::into_inner() will try to flush the buffer before giving you back the underlying Write object, which can fail.
BufWriter::into_parts() cannot fail and gives you the Write object and the unflushed buffer, so you can handle it manually:
13/17
5. A new .shrink_to() method on Vec, String, PathBuf, VecDeque, HashSet, etc.
This allows you to *reduce* the .capacity() of a collection. It is basically the opposite of .reserve():
14/17
6. const mem::transmute() π¬
You can now use std::mem::transmute to do horrible things in a const fn:
15/17
And finally, a new Cargo feature:
7. You can now specify the minimum supported Rust version in your Cargo.toml:
rust-version = "1.56.0"
If specified, Cargo will give users of your crate a clear error when their version of Rust is too old:
16/17
And that's the end of this thread!β¨
For a more complete list of changes in Rust 1.56, check the release notes:
Rust: github.com/rust-lang/rustβ¦
Cargo: github.com/rust-lang/cargβ¦
Clippy: github.com/rust-lang/rustβ¦
And for details on the 2021 edition, see: doc.rust-lang.org/edition-guide/
17/17
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.