Rust 1.95.0 Release: cfg_select! Macro, Improved Match Guards, and More
Overview of Rust 1.95.0
The Rust team is thrilled to announce the release of Rust 1.95.0, the latest stable version of the language renowned for enabling developers to build efficient and reliable software. If you already have Rust installed via rustup, you can upgrade seamlessly with the command:

$ rustup update stable
New to Rust? You can install rustup from the official website. For detailed changes, consult the release notes. Developers eager to test upcoming features can switch to the beta or nightly channels using rustup default beta or rustup default nightly. Please report any issues you encounter!
New Features in Rust 1.95.0
cfg_select! Macro: Streamlined Conditional Compilation
One of the headline features in Rust 1.95.0 is the introduction of the cfg_select! macro. This macro provides a compile-time conditional selection mechanism, similar to the popular cfg-if crate but with its own syntax. It evaluates a series of configuration predicates and expands to the right-hand side of the first arm that evaluates to true.
Here are two practical examples:
cfg_select! {
unix => {
fn foo() { /* unix-specific implementation */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback for all other scenarios */ }
}
}
let is_windows_str = cfg_select! {
windows => "windows",
_ => "not windows",
};
This macro simplifies platform-specific code and reduces boilerplate, making it easier to maintain cross-platform projects.
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 guards within match expressions to add extra conditional logic based on pattern matching. 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 currently does not consider patterns used in if let guards when checking exhaustiveness, similar to how if guards work. This feature allows more expressive and concise matching logic.
Stabilized APIs and Enhancements
Rust 1.95.0 brings a wealth of stabilized APIs, enhancing the standard library’s functionality. Key additions include:
Improved Conversions for MaybeUninit and Cell
- MaybeUninit<[T; N]>: Implemented
From<[MaybeUninit<T>; N]>,AsRefandAsMutfor both[MaybeUninit<T>; N]and[MaybeUninit<T>]. - [MaybeUninit<T>; N]: Now implements
From<MaybeUninit<[T; N]>>. - Cell: Added
AsRefimplementations forCell<[T; N]>andCell<[T]>.
These additions simplify conversions between array and slice representations of MaybeUninit and Cell.
bool: TryFrom<{integer}>
The bool type now implements TryFrom for all integer types, allowing safe conversion from integers (0 becomes false, 1 becomes true, any other value returns an error). This eliminates manual checks and improves code clarity.
Atomic Operations: update and try_update
Several atomic types gain update and try_update methods: AtomicPtr, AtomicBool, and all AtomicIn/AtomicUn (atomic integer and unsigned integer types). These methods provide a convenient way to atomically modify the value using a closure, with try_update returning a boolean indicating success.
Additions to core::range and core::hint
- A new
core::rangemodule has been stabilized, includingcore::range::RangeInclusiveandcore::range::RangeInclusiveIter. core::hint::cold_pathis now stable, allowing developers to hint that a code path is unlikely to be taken, aiding branch prediction.
Unchecked Pointer Dereference Methods
Raw pointers *const T and *mut T now have as_ref_unchecked and as_mut_unchecked methods (for *mut T). These offer a way to dereference pointers without safety checks, useful in performance-critical sections where invariants are upheld by the caller.
New Methods for Vec, VecDeque, and LinkedList
- Vec: Added
push_mutandinsert_mut. - VecDeque: Added
push_front_mut,push_back_mut, andinsert_mut. - LinkedList: Added
push_front_mut(and likely other related methods as per the original release notes).
These methods provide mutable access to elements when pushing or inserting, enabling direct modification without extra steps.
Conclusion
Rust 1.95.0 delivers substantial quality-of-life improvements for Rust developers. The cfg_select! macro and enhanced match guards make conditional compilation and pattern matching more powerful. The stabilized APIs expand the standard library’s versatility, especially in areas like memory management and concurrency. As always, the Rust team encourages you to test upcoming releases via the beta and nightly channels and report any issues. Happy coding!
Related Articles
- How to Master AI-Assisted Coding: A Step-by-Step Guide to Agentic Engineering
- Bridging the Gap: Why Good Designers Create Inaccessible Websites and How to Fix It
- Mastering Windows 11 KB5083631: A Comprehensive Guide to the Latest Optional Update
- 8-Year-Old Boy of African Descent Found Buried Among White Colonists in 17th-Century Maryland – Enslavement Status Unknown
- Fitbit Air: Google's $100 Fitness Band Without a Screen – But a $10 Monthly AI Coach
- Securing Your cPanel Server Against Critical Authentication Flaws: A Step-by-Step Update Guide
- Navigating Unionization and Store Closures: A Case Study of Apple’s Towson Retail Store
- Revive Your Sluggish Fire TV Stick: Practical Solutions Before You Upgrade