|
|
Subscribe / Log in / New account

Announcing Rust 1.56.0 and Rust 2021

The Rust language project has announced the release of stable version 1.56.0 and the Rust 2021 edition.
We wrote about plans for the Rust 2021 Edition in May. Editions are a mechanism for opt-in changes that may otherwise pose backwards compatibility risk. See the edition guide for details on how this is achieved. This is a smaller edition, especially compared to 2018, but there are still some nice quality-of-life changes that require an edition opt-in to avoid breaking some corner cases in existing code.

See the detailed release notes for 1.56.0 for lots more information on the release.

to post comments

Announcing Rust 1.56.0 and Rust 2021

Posted Oct 23, 2021 23:05 UTC (Sat) by tialaramex (subscriber, #21167) [Link] (2 responses)

It's interesting to go back and look at what one had to write in Rust 1.0 and compare to what you write today, remembering that all that Rust 1.0 code still compiles so long as it doesn't claim to be for a newer edition.

For example, in Rust 1.0 if you mean to provide one function for twiddling Things and don't want to require that your callers provide some particular container of Things (such as a Vector) you can instead oblige them to Box up their container on the heap so as to hide its real type from you, writing something like:

fn twiddle(things: Box<IntoIterator<Item= Thing>>)

IntoIterator was relatively new in Rust 1.0 so you might have written Iterator, but Rust's IntoIterator is nicer as a parameter type because it doesn't care whether the parameter you provide is already an iterator or just a container that can be iterated over.

You can't write that twiddle declaration in Rust 2021 today (it's an error because "IntoIterator" isn't a concrete type and you must now write dyn to be explicit if you want dynamic typing) but, you wouldn't want to because you can instead express what you actually cared about, that you just want to make an iterator over things in order to twiddle them and you don't care how it's stored:

fn twiddle(things: impl IntoIterator<Item = Thing>)

However, if you still have code from Rust 1.0 that's in the Rust 2015 edition, you can write this new twiddle function just fine, although of course if you do so your code needs a newer compiler since a Rust 1.0 compiler doesn't know about the impl Trait feature.

Announcing Rust 1.56.0 and Rust 2021

Posted Oct 24, 2021 15:06 UTC (Sun) by bluss (guest, #47454) [Link] (1 responses)

You must mean `Box<Iterator<Item= Thing>>` for Rust 1.0. `IntoIterator` is not (and has not) been usable as a trait object - one can't hide away "convert into specific iterator type" behind a trait object. But `Box<dyn Iterator<Item= Thing>>` (modern spelling) was and remains usable for dynamic dispatch overhead-enabled iterators.

Announcing Rust 1.56.0 and Rust 2021

Posted Oct 24, 2021 19:54 UTC (Sun) by tialaramex (subscriber, #21167) [Link]

D'oh. An earlier draft of my text used Iterator, but, I realised IntoIterator already existed in 2015 and didn't go back and check if you can actually write a boxed IntoIterator which, as you point out, you could not. Thanks for the correction.


Copyright © 2021, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds