Uncategorized

These are the plans for the programming language

The 2021 edition of the increasingly popular Rust programming language is scheduled for October 2021. It contains innovations that are primarily aimed at a better UX – as usual, everything is maximally compatible with the rest of the ecosystem.

Rust is a modern programming language that focuses on thread safety and performance. In contrast to many so-called higher-level programming languages, there is neither garbage collection nor a virtual machine in Rust. Instead, Rust addresses known problems of long-established low-level programming languages ​​such as C or C ++. With some success – interest in the programming language is increasing: Facebook recently joined the Rust Foundation, AWS is investing in further development and Google has announced that it will develop Android system components in Rust in the future.

The release of the new features is planned with the release of version 1.56.0 – the planned release date is October 21.

New features for the Prelude module

The Prelude module of the Rust standard library contains frequently used entities such as Option, Vec, drop and Clone. The Rust compiler prioritized manually imported entities over those of the Prelude module. This ensures that so-called prelude additions do not lead to existing code no longer working. In a crate or module called example, the one pub struct Option contains, would use example::*; instead of Option the standard library clearly this Option from the example– Reference the module.

That’s the theory. Nevertheless, adding a trait can make the code unusable, for example if so-called traits are named the same as those in the standard library. Rust’s team cites this fact as the reason that TryInto was not added to Rust’s Prelude. Instead, Rust should use a new Prelude in 2021. It is identical to the old one, but has three new additions:

Almost finished!

Please click on the link in the confirmation email to complete your registration.

Would you like more information about the newsletter? Find out more now

std::convert::TryInto
std::convert::TryFrom
std::iter::FromIterator

The Cargo Feature Resolver becomes the default

Since Rust 1.51.0, Rust’s package manager Cargo has a feature that allows you to skip package versions that do not have features that are not required. So far, this so-called feature resolver was opt-in, with the new version it will become the default.

Up to V 1.53 only references to arrays implement IntoIterator. That is, over &[1, 2,3] and &mut[1, 2, 3] could be iterated, but not directly over [1, 2, 3].

for &e in &[1, 2, 3] {} // Ok :)
for e in [1, 2, 3] {} // Error :(

Editions in Rust can be used mixed, which precluded the sole implementation in Edition 2021. Instead, it was included in all editions starting with 1.53.0. To avoid incompatibilities, the team also implemented a small workaround for the into_iter()-Method: This is still to be used in Rust 2015 and 2018 (&array).into_iter() resolved – as if the new trait implementation didn’t even exist. Warning: This only applies to into_iter(), Spellings like for e in [1, 2, 3] or IntoIterator::into_iter([1, 2, 3]) will then work in all editions.

According to the blog post, the hack was added because otherwise too much code could simply no longer execute correctly. It only affects older versions; it did not result in any additional complexity in Edition 2021.

Also read: 3 reasons why you should learn Rust in 2021 – and maybe even have fun doing it

Changed closure behavior

As of Edition 2021, closures will only record the fields that they actually use. So far it has been the case that they record everything that is related to within their functional body. So would be a reference a of || a + 1 automatically captured from context. This currently applies to entire structures, even if only one field is used. For example catches || a.x + 1 a reference to a one and not just on a.x.:


let a = SomeStruct::new();
drop(a.x); // Move out of one field of the struct
println!("{}", a.y); // Ok: Still use another field of the struct

let c = || println!("{}", a.y); // Error: Tries to capture all of `a`
c();

As of the new edition, the above code will be compiled without any problems in the future. Because this new behavior can influence the order in which fields are dropped, the new feature should only be activated in the new edition. As with all edition changes, there will be a automatic migration give.

But that wasn’t all. The 2021 edition will come up with a new panic! () Macro, two warnings about explicit error messages have been made and so-called patterns will also be made in the future | support.

All innovations in detail as well as a more detailed explanation of why Rust is being released in Editions can be found in the Blog post the Rust Edition Working Group read.

You might be interested in that too

Leave a Reply

Your email address will not be published. Required fields are marked *