RangeFrom, Part 2..: What I think is wrong about the design

13 points by valdemar


ettolrach

This means that it is not always monotonically increasing since it will stay the same.

To me, the order relation used for monotonicity is usually less than or equal <=, not strictly less than <. In that view, the function is monotonically increasing, since 255 <= 255.

madsmtm

Hmm, after reading this I'm kinda liking the "overflow in release to the start" option? And have that be the behaviour for all of the types in the standard library?

So your table here would just list "Debug: panic!, Release: Overflow to start"

juliaaa

Sort of unrelated, but I've been convinced by a colleague that Range types should default to being inclusive by default.

The primary counter-example being how do you represent ranges that include the uXX::MAX value? This is exactly the issue in this post.

For instance, for i in 0..=255u8 { } is necessary if you want the value to be a u8. With an exclusive range you need an extra bit to be able to represent the full range, since ExclRange { start: 0, end: u64::MAX } doesn't cover the whole range, and ExclRange { start: 0, end: u64::MAX + 1 } obviously doesn't work (and if it did would complicate any kinds of contains() check with edgecades). As far as I know the latter is not possible to represent in Rust's standard Range type since Range { start: 0, end: 0 } is treated as empty.

This is also not documented anywhere in Rust's stdlib documentation about this behaviour and what happens right at the end here. Say you have 0xf0u8 and a size of 0x10, then you'd expect the range Range<u8> { start: 0xf0, end: 0xf0 + 0x10 } to work, but it will instead silently be empty. Whoops.

Inclusive ranges sidestep this problem entirely.