Rust 1.5 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


Mozilla Makes Pyodide Community Project
04/05/2021

Pyodide is now an independent community project rather than being developed in-house at Mozilla. Pyodide provides a way to run Python in web browsers by using a WebAssembly compilation of the CPython  [ ... ]



Is Australia The Best Place For Developers?
16/04/2021

DevSkiller has released its third annual report on IT skills, revealing that Australian developers score the highest on coding tests and that Australia comes second only to Switzerland in terms of ann [ ... ]


More News

square

 



 

Comments




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

Last Updated ( Thursday, 18 February 2021 )