NomalvoDocsTechnology
Related
The Supreme Court's Flawed Logic on Voting Rights and RacismHow Deleted Signal Messages Were Recovered from an iPhone's Push Notification Cache10 Essential Facts About Windows 11 Version 25H2 and Its Latest UpdatesRoblox's User Decline: 10 Key Insights from the Latest Earnings Report10 Critical Kubernetes v1.36 Changes You Must KnowHow the Supreme Court's Louisiana v. Callais Decision Undermines Voting Rights and What It Means for Environmental AdvocacyRevitalizing Legacy Systems: A Practical Guide to UX ModernizationMonarch: Legacy of Monsters Season 3 – What's Next After the Season 2 Finale?

Rust 1.95.0: New Macro, Match Guards, and API Stabilizations

Last updated: 2026-05-03 01:55:55 · Technology

Welcome to the latest stable release of Rust, version 1.95.0! This update brings a new compile-time macro, enhanced pattern matching in match expressions, and a fresh set of stabilized APIs. Whether you're a systems programmer or a hobbyist, these additions aim to improve code clarity and safety. Let's dive into the key changes with a Q&A format.

How do I update to Rust 1.95.0?

If you already have Rust installed via rustup, simply run the following command in your terminal:

Rust 1.95.0: New Macro, Match Guards, and API Stabilizations
Source: blog.rust-lang.org
$ rustup update stable

This will upgrade your current stable toolchain to version 1.95.0. If you haven't installed Rust yet, head to the official website to get rustup. For those eager to test upcoming features, you can switch to the beta or nightly channels using rustup default beta or rustup default nightly. Please report any bugs you encounter on the Rust issue tracker.

What is the cfg_select! macro and how does it work?

Rust 1.95.0 introduces cfg_select!, a macro that acts as a compile-time conditional selector, similar to a match on configuration predicates. It expands to the right-hand side of the first arm whose predicate evaluates to true. For example:

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

This macro serves a similar purpose to the popular cfg-if crate but with a different syntax. It can also be used for inline expressions, like:

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

This makes conditional compilation more concise and readable directly within the language.

How do if-let guards work in match expressions?

Building on let chains stabilized in Rust 1.88, version 1.95.0 brings if let guards into match arms. This allows you to add a pattern-matching condition to a match arm. For instance:

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

Here, the arm matches only if value is Some(x) and compute(x) returns Ok(y). The variables x and y are both in scope inside the arm's block. Note that the compiler does not consider the patterns inside if let guards for exhaustiveness checking, similar to traditional if guards.

What APIs were stabilized in Rust 1.95.0?

This release stabilizes a number of APIs across the standard library. Notable additions include:

  • MaybeUninit conversions: MaybeUninit<[T; N]> now implements From<[MaybeUninit<T>; N]> and related AsRef/AsMut traits.
  • Cell and bool: Cell<[T; N]> gains AsRef implementations, and bool now implements TryFrom<{integer}>.
  • Atomic operations: Various atomic types (AtomicPtr, AtomicBool, AtomicI*, AtomicU*) have new update and try_update methods.
  • New modules and items: The core::range module now includes RangeInclusive and its iterator. Also, core::hint::cold_path is stabilized, and raw pointer methods as_ref_unchecked and as_mut_unchecked are now available.
  • Collection mutations: Vec, VecDeque, and LinkedList have new methods like push_mut, insert_mut, and push_front_mut that return mutable references.

For a complete list, see the detailed release notes.

How can I test future releases of Rust?

If you'd like to help the Rust team by testing upcoming features before they hit stable, you can use the beta or nightly channels. To switch, run:

rustup default beta
# or
rustup default nightly

You can also install a specific channel alongside your current setup without changing defaults. Use rustup toolchain install beta and then cargo +beta build for one-off builds. Remember to report any bugs you find to the Rust issue tracker – your feedback helps make the language better for everyone.

How does cfg_select! compare to the cfg-if crate?

The cfg_select! macro fulfills the same purpose as the popular cfg-if crate: compile-time conditional code selection based on configuration predicates. However, the syntax differs. In cfg_select!, arms are separated by => with a wildcard _ for the fallback, while cfg-if uses a more block-oriented style with if cfg!(...) checks. cfg_select! is built directly into the language, removing the need for an external dependency. It also supports more concise inline expressions, as shown above. Both tools are robust, but the native macro reduces boilerplate and streamlines conditional compilation in Rust projects.