Rust 1.95.0: Streamlined Configuration and Enhanced Pattern Matching
Rust 1.95.0 introduces cfg_select! macro for compile-time config selection, if-let guards in matches, and many stabilized APIs including MaybeUninit conversions and atomic updates.
Introduction
Rust continues to evolve with the release of version 1.95.0, bringing developers powerful new tools for conditional compilation and pattern matching. This update focuses on improving ergonomics and reducing reliance on external crates for common tasks. Whether you're working on cross-platform projects or complex data transformations, Rust 1.95.0 offers features that make code cleaner and more expressive.

Getting Rust 1.95.0
If you already have Rust installed via rustup, upgrading is straightforward. Simply run:
$ rustup update stable
For those new to Rust, head to the official installation page to get started. You can also refer to the detailed release notes for a full list of changes.
What’s New in Rust 1.95.0
The cfg_select! Macro
Conditional compilation in Rust has traditionally relied on the cfg! attribute or the popular cfg-if crate. Rust 1.95.0 introduces the cfg_select! macro, which acts as a compile-time match statement on configuration predicates. It expands to the right-hand side of the first arm whose condition evaluates to true. This simplifies platform-specific or architecture-dependent code without needing an extra dependency.
Here’s an example illustrating its use:
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",
};
The syntax is intuitive and eliminates the need for multiple nested cfg! attributes. The macro is particularly useful when you have several mutually exclusive configurations.
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 arms. You can now use if let as a guard in a match pattern, enabling conditional logic based on further pattern matching.
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 yet consider these if let patterns as part of exhaustiveness checking, similar to plain if guards. This means you may need to include a wildcard arm to ensure your match is exhaustive.
Stabilized APIs
Rust 1.95.0 includes a wide range of stabilized APIs that improve type conversions, atomic operations, and collection manipulations. Below is a categorized list of notable additions:
MaybeUninit and Cell Conversions
MaybeUninit<[T; N]>: From<[MaybeUninit<T>; N]>MaybeUninit<[T; N]>: AsRef<[MaybeUninit<T>; N]>andAsRef<[MaybeUninit<T>]>MaybeUninit<[T; N]>: AsMut<[MaybeUninit<T>; N]>andAsMut<[MaybeUninit<T>]>[MaybeUninit<T>; N]: From<MaybeUninit<[T; N]>>Cell<[T; N]>: AsRef<[Cell<T>; N]>andAsRef<[Cell<T>]>Cell<[T]>: AsRef<[Cell<T>]>
Atomic Operations
AtomicPtr::updateandAtomicPtr::try_updateAtomicBool::updateandAtomicBool::try_updateAtomicI{n}::updateandAtomicI{n}::try_update(for all signed integer widths)AtomicU{n}::updateandAtomicU{n}::try_update(for all unsigned integer widths)
New Core Module and Functions
mod core::rangewithRangeInclusiveandRangeInclusiveItercore::hint::cold_path– a hint to the optimizer that a code path is cold<*const T>::as_ref_uncheckedand<*mut T>::as_ref_unchecked<*mut T>::as_mut_unchecked
Collection Mutability Utilities
Vec::push_mutandVec::insert_mutVecDeque::push_front_mut,VecDeque::push_back_mut, andVecDeque::insert_mutLinkedList::push_front_mut
Additionally, bool now implements TryFrom<{integer}>, allowing safe conversion from integers to booleans.
How to Test Upcoming Releases
If you'd like to help shape future versions of Rust, consider switching to the beta or nightly channel. Use the following commands to update locally:
rustup default beta
rustup default nightly
Please report any bugs you encounter via the issue tracker. Your feedback is invaluable to the Rust team.
Conclusion
Rust 1.95.0 delivers meaningful improvements for both system-level and application-level programming. The cfg_select! macro streamlines conditional compilation, while if-let guards make match expressions more flexible. The stabilized APIs remove friction when working with unsafe code, atomics, and collections. Upgrade today and explore the new possibilities!