HomeTechnologyRust in 2021: these are the plans for the programming language

Rust in 2021: these are the plans for the programming language

The Rust logo. (Image: Lloyd Carr / Shutterstock)

Remember Article

The 2021 edition of the increasingly popular programming language Rust 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 21st.

These innovations are coming

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 prioritizes 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 named example , the one pub struct option would contain use example :: *; instead of Option of the standard library clearly that 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:

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

The Cargo Feature Resolver becomes the default

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

IntoIterator for arrays

Up to V 1.53 only implement references to arrays IntoIterator. That is, about & and &courage[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 started in all Editions at 1.53.0. To avoid incompatibilities, the team also implemented a small workaround for the into_iter () – Method: The in Rust 2015 and 2018 will still be (& array) .into_iter () resolved – as if the new trait implementation didn’t even exist. Attention: This only applies to into_iter () , notations 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 not be executed correctly. It only affects older versions; it did not create any additional complexity in Edition 2021.

Read also: 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 a reference to would be a of || a + 1 automatically from the Captured context. This currently applies to entire structures, even if only one field is used. For example starts || ax + 1 a reference to a and not just on ax :

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

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

c ();

As of the new edition, the above code can 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 also be an automatic migration here.

Other new features

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

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

You might also be interested in

Follow World Weekly News on

Adrian Ovalle
Adrian Ovalle
Adrian is working as the Editor at World Weekly News. He tries to provide our readers with the fastest news from all around the world before anywhere else.

Leave a Reply

Must Read