External Publication
Visit Post

Introduce a way to construct Range from start + length

Rust Internals [Unofficial] March 18, 2026
Source

I think it'd be reasonable to have Range::from_start_and_len and Range::try_from_start_and_len as full functions you can write out (one panicking/wrapping and the other returning an Option), and then we can use ..+ or whatever other operator we want as a shorthand, like how ints have long method names for me to specify that I want .wrapping_add or .saturating_add when it's important to explicitly handle overflow, or I can just use + when I don't need to.

I sometimes write code where Range::try_from_start_and_len(start, len).unwrap_or(/* whatever */) would be important to show that the case where len doesn't fit has been thought about and handled appropriately, and the verbosity isn't that bad when you have LSP-backed completion.

Discussion in the ATmosphere

Loading comments...