Rust 1.95.0 Released: New Macro, Enhanced Pattern Matching, and API Stabilizations
Overview
The Rust programming language has reached version 1.95.0, bringing a set of improvements that streamline development and expand the language's capabilities. Whether you're a seasoned Rustacean or new to the ecosystem, this release introduces features designed to make conditional compilation more intuitive, pattern matching more powerful, and code more robust. Below, we delve into the highlights of this latest stable release.

New cfg_select! Macro
One of the standout additions in Rust 1.95 is the cfg_select! macro, which acts as a compile-time conditional selector. It works similarly to a match statement but evaluates configuration predicates (like cfg attributes) to choose an arm. This eliminates the need for the popular cfg-if crate for many use cases, offering a built-in alternative with a slightly different syntax. The macro expands to the right-hand side of the first arm whose predicate evaluates to true.
Example Usage
The following snippet demonstrates how cfg_select! can be used to define platform-specific code:
cfg_select! {
unix => {
fn foo() { /* Unix-specific logic */ }
}
target_pointer_width = "32" => {
fn foo() { /* Non-Unix, 32-bit logic */ }
}
_ => {
fn foo() { /* Fallback implementation */ }
}
}
let is_windows_str = cfg_select! {
windows => "windows",
_ => "not windows",
};
This makes it easier to write platform-agnostic code without resorting to multiple cfg attributes or external crates.
Enhanced Pattern Matching with if-let Guards
Rust 1.95 builds on the let chains stabilized in Rust 1.88 by bringing conditional pattern matching directly into match expressions. Now you can use if let guards within match arms, enabling more concise and expressive logic.
Example
match value {
Some(x) if let Ok(y) = compute(x) => {
// Both x and y are accessible here
println!("{}, {}", x, y);
}
_ => {}
}
Note that the compiler does not currently consider patterns matched in if let guards as part of exhaustiveness checking, consistent with how regular if guards are handled.
Stabilized APIs
This release stabilizes a wide range of APIs, particularly around MaybeUninit, atomic types, and collection operations. Below is a list of the newly stable items:
MaybeUninit and Cell Conversions
MaybeUninit<[T; N]>: From<[MaybeUninit<T>; N]>MaybeUninit<[T; N]>: AsRef<[MaybeUninit<T>; N]>MaybeUninit<[T; N]>: AsRef<[MaybeUninit<T>]>MaybeUninit<[T; N]>: AsMut<[MaybeUninit<T>; N]>MaybeUninit<[T; N]>: AsMut<[MaybeUninit<T>]>[MaybeUninit<T>; N]: From<MaybeUninit<[T; N]>>Cell<[T; N]>: AsRef<[Cell<T>; N]>Cell<[T; N]>: AsRef<[Cell<T>]>Cell<[T]>: AsRef<[Cell<T>]>
Atomic Operations
bool: TryFrom<{integer}>AtomicPtr::updateAtomicPtr::try_updateAtomicBool::updateAtomicBool::try_updateAtomicIn::updateAtomicIn::try_updateAtomicUn::updateAtomicUn::try_update
Collection Methods
Vec::push_mutVec::insert_mutVecDeque::push_front_mutVecDeque::push_back_mutVecDeque::insert_mutLinkedList::push_front_mutLinkedList::push_back_mutLinkedList::insert_mut
Additional Stabilizations
cfg_select!mod core::rangecore::range::RangeInclusivecore::range::RangeInclusiveItercore::hint::cold_path<*const T>::as_ref_unchecked<*mut T>::as_ref_unchecked<*mut T>::as_mut_unchecked
How to Update
If you have a previous Rust version installed via rustup, updating to 1.95.0 is straightforward. Run the following command:
rustup update stable
If you don't have rustup yet, grab it from the official Rust website. For those eager to test future releases, you can switch to the beta or nightly channels using rustup default beta or rustup default nightly. Please report any issues you encounter on the Rust issue tracker.
Conclusion
Rust 1.95.0 continues the language's tradition of incremental yet impactful improvements. The cfg_select! macro simplifies conditional compilation, if let guards enrich pattern matching, and the newly stabilized APIs offer more flexibility in working with memory, concurrency, and collections. As always, the Rust team encourages you to experiment with these features and provide feedback for future releases.
Related Articles
- A Call to Action: Sharing the American Dream Through Philanthropy and Long-Term Investment
- Tech Giants Open AI Models to Government Safety Audits Before Launch
- LVFS Sustainability Challenge: How Linux Firmware Updates Depend on Vendor Contributions
- Rivian R2: Affordable Adventure Awaits with New Features and Potential In-House Lidar
- How Coupa Used 20 Years of Spend Data to Build an AI-Powered Autonomous Spend Management System
- How to Choose Between Vibe Coding and Spec-Driven Development: A Step-by-Step Guide
- Microsoft Rushes Out Windows 11 Security Overhaul: Third-Party Driver Trust Revoked in New Update
- Design Gap Exposed: Why Most Products Work But Few Work Well, Experts Say