Rust 1.95.0: New Macro, Enhanced Pattern Matching, and More
The Rust team is pleased to announce the release of Rust 1.95.0, the latest stable version of the language that empowers developers to build reliable and efficient software. This release introduces a new compile-time selection macro, extends pattern matching capabilities in match expressions, and stabilizes a significant number of APIs. If you already have Rust installed via rustup, you can update with:
rustup update stableFor those new to Rust, get rustup from the official website. The full release notes are available here. If you'd like to test upcoming features, switch to the beta or nightly channels (rustup default beta or rustup default nightly) and report any bugs you encounter.
New cfg_select! Macro
Rust 1.95.0 introduces the cfg_select! macro, which acts as a compile-time conditional selection tool. It resembles the popular cfg-if crate but with its own syntax. The macro evaluates configuration predicates sequentially and expands to the right-hand side of the first arm that evaluates to true. Here is an example of its usage with functions:

cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}You can also use it inline, as in this string assignment:
let is_windows_str = cfg_select! {
windows => "windows",
_ => "not windows",
};This macro simplifies conditional compilation by eliminating the need for external crates or repetitive cfg! checks, making code more concise and readable.
Enhanced Pattern Matching with if-let Guards
Building on the let chains stabilized in Rust 1.88, version 1.95.0 brings if let guards into match expressions. This allows you to add pattern-matching conditions directly in match arms. For 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 does not currently consider patterns matched in if let guards as part of exhaustiveness checks—similar to regular if guards. This feature enhances expressiveness by allowing complex conditional destructuring without nesting additional match or if let statements.
Stabilized APIs
Rust 1.95.0 stabilizes a wide range of APIs, many of which improve ergonomics for MaybeUninit, Cell, atomics, pointers, and collections. Here are the highlights:
Conversions and References for MaybeUninit
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]>>
Reference Implementations for Cell
Cell<[T; N]>: AsRef<[Cell<T>; N]>Cell<[T; N]>: AsRef<[Cell<T>]>Cell<[T]>: AsRef<[Cell<T>]>
Type Conversions and Atomic Operations
bool: TryFrom<{integer}>— Convert integer types toboolwith error handling.- Atomic pointer and boolean update methods:
AtomicPtr::update,AtomicPtr::try_update,AtomicBool::update,AtomicBool::try_update. - Atomic integer updates:
AtomicIn::update,AtomicIn::try_update,AtomicUn::update,AtomicUn::try_update(whereInandUnrepresent signed and unsigned integer types).
Core and Collections
cfg_select!macro (now stabilized).- New module
core::rangewith typesRangeInclusiveandRangeInclusiveIter. - New hint function
core::hint::cold_pathto guide the optimizer. - Pointer methods:
<*const T>::as_ref_unchecked,<*mut T>::as_ref_unchecked,<*mut T>::as_mut_unchecked. - Collection mutations:
Vec::push_mut,Vec::insert_mut,VecDeque::push_front_mut,VecDeque::push_back_mut,VecDeque::insert_mut,LinkedList::push_front_mut.
These additions improve safety, ergonomics, and performance for low-level and high-level Rust code alike.
Conclusion
Rust 1.95.0 continues the language's tradition of incremental improvement. With the cfg_select! macro, if-let guards in match arms, and a robust set of stabilized APIs, developers gain powerful tools for writing clean, efficient, and context-aware code. Update your toolchain today and explore the new possibilities.
Related Articles
- Breaking: 'RuPaul's Drag Race All Stars 11' Premieres Tonight with 18 Queens, Three Brackets, and a Historic Two-Episode Debut
- Navigating Leadership Changes: The Latest Executive Movements in Biopharma
- Windows 11 KB5083631 Optional Update: Key Changes and Fixes Explained
- 6 Surprising Facts About Samsung's One UI 8.5 Rollout for the Galaxy Z Flip 7 FE
- From Skeptic to Devotee: The Ultimate Guide to Choosing and Using Sleep Earbuds
- How to Extract Actionable Insights from the 34th Technology Radar
- 6 Key Implications of Kubernetes SELinux Volume Labels Going GA in v1.37
- Kubernetes v1.37 to Enable SELinux Mount Optimization: Faster but Potentially Breaking for Shared Volumes