Rust 1.95.0: Key Features and Enhancements
By
<p>Welcome to the latest stable release of Rust, version 1.95.0! This update brings powerful new tools to make your code more expressive and safer. Whether you're a seasoned Rustacean or just starting out, there's something here for you. Let's dive into the highlights, from a new compile-time configuration macro to improved pattern matching capabilities. If you haven't updated yet, simply run <code>rustup update stable</code> to get the latest goodness.</p>
<h2 id="install-update">How do I install or update to Rust 1.95.0?</h2>
<p>If you already have Rust installed via <code>rustup</code>, updating is a breeze. Open your terminal and run:</p><figure style="margin:20px 0"><img src="https://www.rust-lang.org/static/images/rust-social-wide.jpg" alt="Rust 1.95.0: Key Features and Enhancements" style="width:100%;height:auto;border-radius:8px" loading="lazy"><figcaption style="font-size:12px;color:#666;margin-top:5px">Source: blog.rust-lang.org</figcaption></figure>
<pre><code>rustup update stable</code></pre>
<p>This command fetches the latest stable release and sets it as your default toolchain. If you don't have <code>rustup</code> yet, head over to the official <a href="https://rustup.rs/">Rust website</a> to get it. Once installed, you can also test upcoming features by switching to the beta or nightly channels with <code>rustup default beta</code> or <code>rustup default nightly</code>. Your feedback on those channels helps shape future releases!</p>
<h2 id="cfg-select-macro">What is the new <code>cfg_select!</code> macro and how does it work?</h2>
<p>Rust 1.95.0 introduces <code>cfg_select!</code>, a macro that lets you perform compile-time branching based on configuration predicates. Think of it as a <code>match</code> for <code>cfg</code> conditions. The macro expands to the right-hand side of the first arm whose predicate evaluates to <code>true</code>. For example:</p>
<pre><code>cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}</code></pre>
<p>This replaces the popular <code>cfg-if</code> crate with a built-in solution, though the syntax differs slightly. You can also use it in expressions, like <code>cfg_select! { windows => "windows", _ => "not windows" }</code>. It's a clean way to handle platform-specific code without relying on external libraries.</p>
<h2 id="if-let-guards">What are <code>if-let</code> guards in match expressions?</h2>
<p>Building on the let chains stabilized in Rust 1.88, version 1.95.0 brings <code>if-let</code> guards into <code>match</code> arms. This allows you to add additional pattern-matching conditions within a match. For instance:</p>
<pre><code>match value {
Some(x) if let Ok(y) = compute(x) => {
// Both `x` and `y` are available here
println!("{}, {}", x, y);
}
_ => {}
}</code></pre>
<p>Here, the <code>if let</code> guard runs <code>compute(x)</code> and only enters the arm if it returns <code>Ok(y)</code>. This keeps your code concise and avoids nested matches. Note that the compiler does not consider patterns inside <code>if-let</code> guards for exhaustiveness checking (similar to regular <code>if</code> guards), so you may still need a wildcard arm.</p>
<h2 id="stabilized-apis">What are some of the newly stabilized APIs in Rust 1.95.0?</h2>
<p>This release stabilizes a large set of APIs, particularly around <code>MaybeUninit</code>, <code>Cell</code>, and atomics. Key additions include:</p>
<ul>
<li><strong>MaybeUninit<[T; N]></strong>: Now implements <code>From</code>, <code>AsRef</code>, and <code>AsMut</code> conversions between arrays and slices.</li>
<li><strong>Cell<[T; N]></strong>: Added <code>AsRef</code> implementations for arrays and slices.</li>
<li><strong>bool: TryFrom<{integer}></strong>: Allows safe conversion from integers to booleans.</li>
<li><strong>Atomic operations</strong>: <code>AtomicPtr</code>, <code>AtomicBool</code>, and atomic integer types now have <code>update</code> and <code>try_update</code> methods.</li>
<li><strong>Vec and VecDeque</strong>: New methods like <code>push_mut</code>, <code>insert_mut</code> provide in-place modification of elements.</li>
<li><strong>Raw pointer methods</strong>: <code>as_ref_unchecked</code> and <code>as_mut_unchecked</code> for <code>*const T</code> and <code>*mut T</code>.</li>
</ul>
<p>These additions improve ergonomics and safety when working with low-level memory and concurrency.</p>
<h2 id="core-range">What is the new <code>core::range</code> module?</h2>
<p>Rust 1.95.0 stabilizes the <code>core::range</code> module, which provides additional range types and iterators. Notably, it includes <code>RangeInclusive</code> and <code>RangeInclusiveIter</code>. These are similar to the existing inclusive range (<code>..=</code>) but with more explicit types for generic programming. This module helps standardize range-related utilities that were previously only available in <code>std</code> or external crates.</p>
<h2 id="other-notable">Are there any other notable additions or changes?</h2>
<p>Yes! The <code>core::hint::cold_path</code> function is now stable. It marks a branch as unlikely to be taken, helping the compiler optimize code paths. Additionally, several collection types like <code>LinkedList</code> gained <code>push_front_mut</code> and similar methods for in-place mutation. These small enhancements make everyday Rust coding more convenient and performant. For the full list of changes, check out the detailed <a href="https://blog.rust-lang.org/2025/01/30/Rust-1.95.0.html">release notes</a>.</p>