Rust team polishes matches! and subslice patterns in 1.42 release

The team behind programming language Rust has prepped version 1.42 for download, providing devs with expanded support for matching on parts of a slice and a stabilised macro for pattern matching.

The now available release allows developers to use the slice pattern syntax with subslices, which can be useful for matching purposes. Subslice patterns are introduced via .. which is meant to denote “a variable-length gap, matching as many elements as possible not matched by the patterns before and after the ..”.

Users who were looking for a simple form of pattern matching in Rust will be pleased to learn that the matches! macro is now stable enough to use. It accepts an expression and a pattern as well as features like | patterns and if guards, and returns true if the two are a match. Other than that the new version comes with stabilised iterations of the CondVar::wait_while, CondVar::wait_timeout_while, DebugMap::key, DebugMap::value, ManuallyDrop::take, ptr::slice_from_raw_parts_mut, and ptr::slice_from_raw_parts API.

The Rust team has also added a way for users to create enums with the exact layout and ABI of the type it contains, and reworked the compiler so that it now produces panic messages pointing to where they were called to be more useful.

Advertisement

In terms of library changes, devs can now derive partial and regular equations from io::Cursor, and use Pin::{map_unchecked, map_unchecked_mut} on return types without an implementation of Sized. Meanwhile iter::Empty<T> implements Send and Sync functions for any T, and the standard library can be used for riscv64gc-unknown-linux-gnu.

Rust’s package manager Cargo now automatically adds the proc_macro crate to the extern prelude for proc-macro packages, making extern crate proc_macro unnecessary for proc-macros. Moreover devs can use –versioned-dirs on cargo vendor in the new version, forcing it to include version numbers in a package’s directory name. To help those new to the tool, the release also includes updated documentation, which is meant to give more pointers on things like git authentication, Cargo targets, workspaces, and features. 

Updating to Rust 1.42 should be fairly straightforward. The only compatibility note given mentions that Error::description has been deprecated, so devs should go with Display/to_string instead. A complete list of changes can be found in the language’s project repository.

- Advertisement -