Rust 1.95.0: Introducing cfg_select! and Enhanced Pattern Matching

By

Rust 1.95.0 Has Arrived

The Rust team is proud to announce the release of Rust version 1.95.0, a significant update that brings powerful new tools to the language. As always, Rust continues to empower developers to build reliable and efficient software. If you already have Rust installed via rustup, upgrading is simple:

Rust 1.95.0: Introducing cfg_select! and Enhanced Pattern Matching
Source: blog.rust-lang.org
$ rustup update stable

If you need to install rustup for the first time, visit the official download page. For those eager to test upcoming features, you can switch to the beta or nightly channels (rustup default beta or rustup default nightly) and report any bugs you encounter.

Key Features in Rust 1.95.0

The cfg_select! Macro

One of the headline additions is the cfg_select! macro, which performs compile-time branching based on configuration predicates. It functions similarly to the popular cfg-if crate but with its own syntax. The macro expands to the right-hand side of the first arm whose condition evaluates to true. This is invaluable for writing platform-specific or architecture-specific code without manually nesting cfg attributes.

Example usage:

cfg_select! {
    unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}

let is_windows_str = cfg_select! {
    windows => "windows",
    _ => "not windows",
};

This macro simplifies conditional compilation, making your code cleaner and more maintainable.

if-let Guards in match Expressions

Building on the let chains stabilized in Rust 1.88, Rust 1.95 now allows if let guards inside match arms. This enables pattern matching combined with conditional logic directly within match clauses.

Example:

match value {
    Some(x) if let Ok(y) = compute(x) => {
        // Both `x` and `y` are available here
        println!("{}, {}", x, y);
    }
    _ => {}
}

Note that the compiler currently does not consider patterns in if let guards for exhaustiveness checking—similar to existing if guards. This feature adds expressive power to match statements without breaking existing behavior.

Stabilized APIs

Rust 1.95.0 stabilizes a wide array of APIs, many of which improve ergonomics for MaybeUninit, Cell, and atomic types. Here’s the full list:

These additions enhance type safety, performance, and ease of use for common patterns. For full details, see the official release notes.

Conclusion

Rust 1.95.0 is a substantial release that brings practical improvements like cfg_select! and if let guards, alongside many stabilized APIs. The Rust team continues to refine the language based on community feedback. Upgrade today and explore these new capabilities. As always, happy coding!

Tags:

Related Articles

Recommended

Discover More

GIMP 3.2.4 Delivers Critical Layer Fixes and Stability EnhancementsHow to Analyze a Major Stake Purchase in a Tech Finance Company Using SEC FilingsPerplexity's Mac-First 'Personal Computer' Platform: Your Top Questions AnsweredMaking Man Pages More User-Friendly: Insights from rsync, strace, and perlcheatSharpen Your DM Skills with This Unique Book-Based RPG