-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
This is a small enhancement request, that (as it usually happens) I am not sure about, but I like it.
Like u32::BITS I'd like another constant for all Rust integral numbers XX (i8, u8, i16, u16, etc):
XX::RANGE: RangeInclusive<XX> = XX::MIN ..= XX::MAX;
So you can write:
for i in u8::RANGE { ... }
That's shorter, is more DRY and avoids mistakes like (that is forgetting that a signed number doesn't start at zero, and missing the last number of the range):
for i in 0 ..= i8::MAX {}
for i in i8::MIN .. i8::MAX {}
I think this could be useful now, but it will become even more handy if/when Rust adds ranged integers as in Ada, see:
https://en.wikibooks.org/wiki/Ada_Programming/Attributes/%27Range
I think it's better not to define char::RANGE.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.