Tuesday, June 30, 2026

Rust introduces new Range types | Latest Update

Rust introduces new Range types

Rust 1.96.0 has arrived, bringing new Range* types to the programming language known for its memory safety.

Announced May 28, Rust 1.96.0 can be installed by current users by running the command rustup update stable.

In elaborating on the new Range* types, the Rust team said many users expect Range and related core::ops types to be Copy, but this is not the case. These types implement Iterator directly, so “it is a footgun to implement both Iterator and Copy on the same type”. RFC3550 proposed replacement range types that implement IntoIterator rather than Iterator, meaning they also can be Copy. The standard library portion of that RFC is now stable, introducing the types core::range::Range, core::range::RangeFrom, core::range::RangeInclusive, and associated iterators.

A future Rust version will add core::range::RangeFull and core::range::RangeTo as re-exports from core::ops. These do not implement Iterator and already implement Copy, the Rust team said. A future Rust version will also introduce core::range::legacy::* as the new home for the current ranges. Range syntax like 0..1 still produces the legacy types for now, the Rust team said, but will be updated to core::range types in an upcoming edition. With these stabilizations, it is now possible to store slice accessors in Copy types without splitting start and end, according to the team. Additionally, the new RangeInclusive type makes its fields public, unlike the legacy version that avoided exposing the exhausted iterator state.

Elsewhere in Rust 1.96.0, two new macros, assert_matches! and debug_assert_matches!, check that a value matches a given pattern, panicking with a Debug representation of the value otherwise. And WebAssembly targets no longer pass --allow-undefined to the linker, which means that undefined symbols when linking are now a linker error instead of being converted to WebAssembly imports from the "env" module. This change prevents modules from linking unless all linking-related symbols are defined to catch bugs earlier and prevent accidental issues with symbol naming or similar.

The Rust team on June 30 published a point release, Rust 1.96.1, which offers a series of fixes for Cargo, MIR, and libssh2:


Source: Rust introduces new Range types | InfoWorld

Previous Post
Next Post

post written by: