Rust 1.95.0 Arrives: New Macro, Enhanced Pattern Matching, and More

By
<h2>Introduction</h2> <p>The Rust team has unveiled version 1.95.0 of the language, continuing its mission to empower developers to build reliable and efficient software. This release introduces two major features: a compile-time conditional macro and improved pattern matching in match expressions, along with a host of stabilized APIs that expand the standard library's capabilities.</p><figure style="margin:20px 0"><img src="https://www.rust-lang.org/static/images/rust-social-wide.jpg" alt="Rust 1.95.0 Arrives: New Macro, Enhanced Pattern Matching, and More" 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> <p>If you already have Rust installed via <code>rustup</code>, updating is straightforward:</p> <pre><code>$ rustup update stable</code></pre> <p>For those new to Rust, visit the official website to get <code>rustup</code>. Detailed release notes for 1.95.0 are available online. Community members are encouraged to test upcoming releases by switching to the beta or nightly channels (<code>rustup default beta</code> or <code>rustup default nightly</code>) and reporting any bugs encountered.</p> <h2 id="cfg_select">New Compile-Time Conditional: <code>cfg_select!</code></h2> <p>Rust 1.95.0 introduces the <code>cfg_select!</code> macro, which provides a clean, compile-time alternative to the popular <code>cfg-if</code> crate. This macro works like a <code>match</code> on configuration predicates, expanding to the right-hand side of the first arm whose condition evaluates to <code>true</code>. The syntax differs from <code>cfg-if</code> but remains intuitive:</p> <pre><code>cfg_select! { unix =&gt; { fn foo() { /* Unix-specific functionality */ } } target_pointer_width = &quot;32&quot; =&gt; { fn foo() { /* Non-Unix, 32-bit functionality */ } } _ =&gt; { fn foo() { /* Fallback implementation */ } } } let is_windows_str = cfg_select! { windows =&gt; &quot;windows&quot;, _ =&gt; &quot;not windows&quot;, };</code></pre> <p>This macro is particularly useful for writing platform-specific code without relying on external crates, reducing dependencies and streamlining conditional compilation.</p> <h2 id="if-let-guards">Enhanced Pattern Matching: <code>if let</code> Guards in <code>match</code></h2> <p>Following the stabilization of let chains in Rust 1.88, version 1.95.0 extends conditional pattern matching into <code>match</code> expressions with <code>if let</code> guards. This allows you to combine pattern matching with an additional <code>if let</code> condition directly inside a match arm:</p> <pre><code>match value { Some(x) if let Ok(y) = compute(x) =&gt; { // Both x and y are available here println!(&quot;{}, {}&quot;, x, y); } _ =&gt; {} }</code></pre> <p>Note that the compiler does not currently consider patterns in <code>if let</code> guards when evaluating exhaustiveness—similar to how ordinary <code>if</code> guards are treated. This feature adds flexibility to complex matching scenarios without breaking existing checks.</p> <h2 id="stabilized-apis">Stabilized APIs in Rust 1.95.0</h2> <p>This release stabilizes a broad set of APIs, many of which improve ergonomics for working with <code>MaybeUninit</code>, atomics, collections, and raw pointers. Below is the complete list of additions:</p> <h3>MaybeUninit and Array Conversions</h3> <ul> <li><code>MaybeUninit&lt;[T; N]&gt;: From&lt;[MaybeUninit&lt;T&gt;; N]&gt;</code></li> <li><code>MaybeUninit&lt;[T; N]&gt;: AsRef&lt;[MaybeUninit&lt;T&gt;; N]&gt;</code></li> <li><code>MaybeUninit&lt;[T; N]&gt;: AsRef&lt;[MaybeUninit&lt;T&gt;]&gt;</code></li> <li><code>MaybeUninit&lt;[T; N]&gt;: AsMut&lt;[MaybeUninit&lt;T&gt;; N]&gt;</code></li> <li><code>MaybeUninit&lt;[T; N]&gt;: AsMut&lt;[MaybeUninit&lt;T&gt;]&gt;</code></li> <li><code>[MaybeUninit&lt;T&gt;; N]: From&lt;MaybeUninit&lt;[T; N]&gt;&gt;</code></li> </ul> <h3>Cell and AsRef Improvements</h3> <ul> <li><code>Cell&lt;[T; N]&gt;: AsRef&lt;[Cell&lt;T&gt;; N]&gt;</code></li> <li><code>Cell&lt;[T; N]&gt;: AsRef&lt;[Cell&lt;T&gt;]&gt;</code></li> <li><code>Cell&lt;[T]&gt;: AsRef&lt;[Cell&lt;T&gt;]&gt;</code></li> </ul> <h3>Atomic Operations</h3> <ul> <li><code>bool: TryFrom&lt;{integer}&gt;</code></li> <li><code>AtomicPtr::update</code></li> <li><code>AtomicPtr::try_update</code></li> <li><code>AtomicBool::update</code></li> <li><code>AtomicBool::try_update</code></li> <li><code>AtomicIn::update</code></li> <li><code>AtomicIn::try_update</code></li> <li><code>AtomicUn::update</code></li> <li><code>AtomicUn::try_update</code></li> </ul> <h3>Additional Stabilizations</h3> <ul> <li><code>cfg_select!</code> (macro)</li> <li><code>mod core::range</code></li> <li><code>core::range::RangeInclusive</code></li> <li><code>core::range::RangeInclusiveIter</code></li> <li><code>core::hint::cold_path</code></li> <li><code>&lt;*const T&gt;::as_ref_unchecked</code></li> <li><code>&lt;*mut T&gt;::as_ref_unchecked</code></li> <li><code>&lt;*mut T&gt;::as_mut_unchecked</code></li> <li><code>Vec::push_mut</code></li> <li><code>Vec::insert_mut</code></li> <li><code>VecDeque::push_front_mut</code></li> <li><code>VecDeque::push_back_mut</code></li> <li><code>VecDeque::insert_mut</code></li> <li><code>LinkedList::push_front_mut</code></li> <li><code>LinkedList::push_back_mut</code></li> </ul> <h2>Conclusion</h2> <p>Rust 1.95.0 continues the language's tradition of incremental, practical improvements. The <code>cfg_select!</code> macro simplifies compile-time conditionals, while <code>if let</code> guards expand pattern matching capabilities. The stabilized APIs bring more ergonomic implementations for memory initialization, atomic operations, and collection manipulation. As always, the Rust community encourages testing and feedback to help shape future releases.</p>
Tags:

Related Articles