Rust 1.50 Improves Array Indexing
Written by Kay Ewbank   
Thursday, 18 February 2021

The Rust team has announced a new release that offers improved array indexing, expanded safe access to union fields, and additions to the standard library.

Rust was originally sponsored by Mozilla, and is intended for use in situations including embedding in other languages, writing programs with specific space and time requirements, and writing low-level code, like device drivers and operating systems. The development of Rust has just been safeguarded by the creation of the Rust Foundation, a cross-industry body aimed at supporting the language and its developers.

rust

The first improvement to the new release is support for const-generic array indexing. This is part of the team's work towards stable const generics, and specifically this release adds implementations of ops::Index and IndexMut for arrays. The indexing operator already worked on arrays through built-in compiler magic, but the library traits weren't  actually implemented at the type level until now.

Support has also been added for value repetition for arrays. This has actually worked as an accidental side effect of another change since Rust 1.38, but has now been formally included. The team says that in the future, to avoid such "temporary" named constants, you can look forward to inline const expressions.

Union fields are another area to have been improved, and it's now possible to safely make assignments to ManuallyDrop<T> union fields. This feature was added as part of an earlier improvement to supporting Drop for unions, but ManuallyDrop<T> doesn't need to Drop, so now Rust 1.50 allows safe assignments to these fields as well.

The handling of Rust's File on Unix platforms has also been corrected. Rust treats some invalid values as a 'niche', and this space may be used for type layout optimizations. On Unix platforms, Rust's File is simply made of the system's integer file descriptor, and this happens to have a possible niche as well because it can never be -1. This niche is now added to the type's definition so it can be used in layout optimizations.

Elsewhere, nine new stable functions have been added to the library including a variety of clamp functions to restrict a value to a certain interval. A number of other functions have been made const.

rust

rust

More Information

Rust Website

Related Articles

Rust Team Announces Rust Foundation

Rust Survey 2020

Amazon AWS Invests In Rust

Rust 2018 Released To Improve Developer Productivity

Rust Survey Revelations

Rust 1.28 Improves Memory Use

Rust 1.26 Adds Existential Types

Rust 1.24 Adds Reformatter

Rust 1.23 Uses Less Memory

Rust 1.20 Adds Associated Contents

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


AI At edX With 30% Savings
13/12/2024

edX is offering a 30% discount on selected courses and program bundles until December 19th. We look at  AI-related certifications that could boost your resume in 2025.



1000 Programmer's Mugs
06/12/2024

It is legend that programmers run on coffee so what better as a festive gift than a new mug with an appropriate slogan? You could boost your favourite programmer's performance by encouraging increased [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Monday, 21 June 2021 )