.mobaxterm19436666DocsTechnology
Related
How to Extract Actionable Insights from the 34th Technology RadarRevive Your Old Google Home Mini with an Affordable Upgrade BoardGitHub Overhauls Status Page with New Severity Levels and Per-Service Uptime MetricsNVIDIA and Google Cloud Unveil Next-Gen AI Infrastructure for Agentic and Physical AIDecoding Palantir's Record Quarter: A Practical Guide to Earnings Report AnalysisFBI Recovers Deleted Signal Messages from iPhone Push Notification Database, Forensic Experts Warn of Privacy RisksHow to Control Playback Speed on Spotify for Podcasts and Prepare for Music10 Key Updates in Safari Technology Preview 240 You Should Know

Rust 1.95.0 Released: Introducing cfg_select! and Improved Pattern Matching

Last updated: 2026-05-06 22:03:09 · Technology

What's New in Rust 1.95.0

The Rust team has announced the release of version 1.95.0, bringing significant enhancements to the language's conditional compilation and pattern matching capabilities. This update focuses on reducing boilerplate while maintaining Rust's core safety guarantees. Developers will find the new cfg_select! macro and improved match expressions particularly valuable for writing cleaner, more maintainable code.

Rust 1.95.0 Released: Introducing cfg_select! and Improved Pattern Matching
Source: blog.rust-lang.org

Updating to Rust 1.95.0

If you already have Rust installed via rustup, obtaining the latest stable release is straightforward:

$ rustup update stable

New users can install rustup from the official Rust website. For those interested in testing upcoming features, you can switch to the beta or nightly channels:

$ rustup default beta
$ rustup default nightly

We encourage all users to report any bugs they encounter on the GitHub issue tracker.

The cfg_select! Macro

Conditional compilation has long been a necessity in Rust, especially for cross-platform development. The cfg-if crate has been a popular solution, but Rust 1.95.0 now offers an official alternative: cfg_select!. This macro works like a compile-time match on configuration predicates, expanding to the right-hand side of the first matching arm.

Basic Usage

The macro accepts any number of arms, each consisting of a configuration predicate and a corresponding expression or block:

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

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

The underscore (_) serves as a catch-all, similar to the default arm in a match expression. This feature streamlines conditional code without relying on external crates.

if-let Guards in Match Expressions

Building on the let chains stabilized in Rust 1.88, version 1.95.0 extends this capability to match expressions. You can now use if let guards to combine pattern matching with conditional logic inside a single match arm:

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

This syntax keeps your code concise and expressive, eliminating the need for nested if let statements. Note that the compiler currently does not consider patterns in if let guards when checking exhaustiveness, so you may need to add a wildcard arm.

Stabilized APIs

Rust 1.95.0 stabilizes a number of APIs that improve ergonomics and safety. Here is a categorized overview:

Conversions and References for MaybeUninit and Cell

  • MaybeUninit<[T; N]>: From<[MaybeUninit<T>; N]>
  • MaybeUninit<[T; N]>: AsRef<[MaybeUninit<T>; N]> and AsRef<[MaybeUninit<T>]>
  • MaybeUninit<[T; N]>: AsMut<[MaybeUninit<T>; N]> and AsMut<[MaybeUninit<T>]>
  • [MaybeUninit<T>; N]: From<MaybeUninit<[T; N]>>
  • Cell<[T; N]>: AsRef<[Cell<T>; N]> and AsRef<[Cell<T>]>
  • Cell<[T]>: AsRef<[Cell<T>]>

Integer to Boolean Conversion

  • bool: TryFrom<{integer}>

Atomic Operations

  • AtomicPtr::update and AtomicPtr::try_update
  • AtomicBool::update and AtomicBool::try_update
  • AtomicIn::update and AtomicIn::try_update
  • AtomicUn::update and AtomicUn::try_update

Core Range and Hint

  • mod core::range with core::range::RangeInclusive and core::range::RangeInclusiveIter
  • core::hint::cold_path

Raw Pointer Safety

  • <*const T>::as_ref_unchecked
  • <*mut T>::as_ref_unchecked and <*mut T>::as_mut_unchecked

Collection Mutators

  • Vec::push_mut and Vec::insert_mut
  • VecDeque::push_front_mut, VecDeque::push_back_mut, and VecDeque::insert_mut
  • LinkedList::push_front_mut

For a complete list, refer to the detailed release notes.

Conclusion

Rust 1.95.0 continues the language's tradition of empowering developers with safe, efficient tools. The cfg_select! macro reduces reliance on third-party crates, while if-let guards in match expressions make pattern matching more flexible. Combined with the newly stabilized APIs, this release is a solid step forward for the ecosystem. Update today and give these features a try!