Back to Home

Rust 1.94.0: New Methods and Cargo Configuration | IT Review

Rust 1.94.0 Release Includes Stabilization of array_windows Method for Processing Fixed-Length Windows, Support for include Key in Cargo Configuration Files and Transition to TOML 1.1. These Changes Simplify Writing Safe and Readable Code, as Well as Flexible Project Configuration. Update Recommended for All Rust Developers.

Rust 1.94.0: How New Features Will Improve Your Code? Release Details
Advertisement 728x90

Rust 1.94.0: array_windows Stabilization, include in Configs, and Transition to TOML 1.1

Rust 1.94.0 has been released, bringing several significant improvements for developers. Key new features include the array_windows method for iterating over fixed-length arrays, support for the include key in Cargo config files, and the switch to TOML 1.1. Here's how these changes will simplify your work.

The array_windows Method: Working with Fixed-Length Windows

In the new version of Rust, the array_windows method for slices has been stabilized. It allows iterating over a slice with fixed-length windows, eliminating the need for manual indexing and bounds checking. Unlike the windows method, which returns slices of dynamic length (&[T]), array_windows returns references to fixed-length arrays (&[T; N]).

This is especially useful in tasks where you need to process consecutive elements with a known window size. For example, to find the ABBA pattern (two different letters followed by their reverse order) in a string, you can use the following code:

Google AdInline article slot
fn has_abba(s: &str) -> bool {
    s.as_bytes()
        .array_windows()
        .any(|[a1, b1, b2, a2]| (a1 != b1) && (a1 == a2) && (b1 == b2))
}

The compiler automatically infers the window length (4) from the destructuring pattern in the closure. With windows(4), you'd have to manually check indices, which is less safe and readable.

Managing Cargo Configuration with the include Key

Cargo now supports the include key in config files (.cargo/config.toml). This feature simplifies organizing, sharing, and managing configurations across projects and environments.

The include key can be an array of paths or an inline table with additional options. For example:

Google AdInline article slot
# Array of paths
include = [
    "frodo.toml",
    "samwise.toml",
]

# Inline tables for fine-tuning
include = [
    { path = "required.toml" },
    { path = "optional.toml", optional = true },
]

The optional = true option allows specifying that a file may be absent in some environments (e.g., on a developer's local machine). This increases config flexibility without needing separate branches.

Switch to TOML 1.1: What's Changed

Cargo now fully supports TOML 1.1 for manifests and config files. This includes several convenient improvements:

  • Ability to span inline tables across multiple lines with trailing commas.
  • New escape sequences for strings: \xHH and \e.
  • Optional seconds in time representations (default: 0).

Example of a multiline inline table:

Google AdInline article slot
serde = {
    version = "1.0",
    features = ["derive"],
}

Note: Using new TOML 1.1 features in Cargo.toml raises the minimum supported Rust version (MSRV) to one requiring the new Cargo parser. However, when publishing a crate, Cargo automatically rewrites the manifest into a format compatible with older parsers. This lets you maintain support for earlier Rust versions for your crate's users.

Stabilized APIs: Full List

Release 1.94.0 stabilizes many APIs that were previously in development. Here are the main ones:

  • Slice methods: <[T]>::array_windows, <[T]>::element_offset
  • LazyCell methods: get, get_mut, force_mut
  • LazyLock methods: get, get_mut, force_mut
  • Conversion: impl TryFrom<char> for usize
  • Peekable methods: next_if_map, next_if_map_mut
  • Intrinsic functions for x86 (AVX-512 FP16) and AArch64 (NEON FP16), except those depending on the unstable f16 type
  • Math constants: f32::consts::EULER_GAMMA, f64::consts::EULER_GAMMA, f32::consts::GOLDEN_RATIO, f64::consts::GOLDEN_RATIO
  • f32::mul_add and f64::mul_add methods are now stable in const contexts

These changes expand the standard library's capabilities and make code more expressive.

Key Takeaways for Developers

  • Simplified window handling: The array_windows method reduces boilerplate code when working with fixed windows, improving safety and readability.
  • Config flexibility: The include key in Cargo allows modular config assembly, which is especially useful for large projects and teams.
  • TOML 1.1 compatibility: New TOML features make config files more convenient, but keep MSRV in mind when using them in Cargo.toml.
  • Standard library expansion: Stabilizing new APIs—including math constants and iterator methods—simplifies everyday tasks.

Updating to Rust 1.94.0 is recommended for all developers to take advantage of these improvements. Use the command rustup update stable to install.

— Editorial Team

Advertisement 728x90

Read Next