Programming language: Rust 1.58 expands format strings and narrows the path


The Rust team has released version 1.58 of the programming language in a scheduled six-week cycle. The third release in the Rust 2021 edition brings only a few innovations. The expansion of format strings and the adjustments to the struct are particularly noteworthy Command on Windows.

Format strings can accept arguments from the environment via an identifier enclosed in curly brackets. Previously, these had to be directly in the instruction and be identifiable by their position or their name. With Rust 1.58, the arguments can also be previously defined in the same scope, as in the following small example from the Rust blog:

// Neu in Rust 1.58:

let person = get_person();
// ...
println!("Hello, person!"); // captures the local `person`

// Schon vorher erlaubt:

println!("Hello, !", get_person());        // implicit position
println!("Hello, 0!", get_person());       // explicit index
println!("Hello, person!", person = get_person()); // named

The identifiers can be used not only for text parts, but also for formatting parameters such as width$ use. However, Rust only processes pure identifiers. If you want to use expressions or other complex integrations in format strings, you must first assign them to an identifier or integrate the expression directly into the statement as in the previous procedure.

In Rust 2021, which started with version 1.56, the integration of the identifiers also works in panic!-Macros that version 1.57 had stabilized for extended use. Rust 2015 and 2018 process the content of panic!("ident") however, not as a format string but as an unformatted string. In interaction with the older editions, the compiler therefore spits out a warning that the command will probably not have the desired effect.

On Windows, the current Rust release narrows the search path for executable files. The structure std::process::Command no longer includes the current directory. The behavior is the historical working of the createProcess-API owed on Windows.

The command prompt under Windows also takes the current directory in the path, but PowerShell does not for security reasons. The makers of the Go programming language also recognized the security gap in 2021. Since then ignored the command go-get the current directory on Windows.

With the adjustment, Rust removes another legacy from the search path and no longer includes the 16-bit Windows system directory.

Other innovations in Rust 1.58 such as the extended use of #[must_use] in the standard library can be found on the Rust blog. As usual, developers who already have Rust installed can update the current release rustup update stable download. For those not yet using Rust, the rustup tool is available separately on the downloads page.


(rm)

To home page



Source link -64