-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ER] Int::RANGE constants #77397
Comments
Since we now have |
If you think that iterating on chars like that could be done efficiently, then ignore my comment, I've commented out that line. (But so far in my code far I've never had to scan a range of chars like that (scanning a small subrange of chars is reasonably common)).
I have some scans of ranges (in mathematical code), in loops where I look for the first integer value that satisfies a predicate. So scanning a usize or u64 isn't uncommon for me because I have a stopping condition. (But still using u64::RANGE isn't going to be common because most times I don't start from zero, but from 2 or some other small value). As I hinted in the first post, scanning a full range of values could be more common once/if Rust adds a syntax to define subranges, like: type MyIdx = usize[1 ..= 12]; At that point using |
Even then, though, I'd probably just use If this is mostly dependent on subrange types, then I think this should just be a note in an item in the rfcs repo, since as I understand rust-lang/rfcs#2979 they're looking at cleaning up issues here. Or if you think this is useful enough now to pull its weight it can just be a PR. (But of course I'm not on libs, so I might be wrong.) |
You are a kind person. I don't know if this could be useful enough. Perhaps not. Others need to judge. |
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):
So you can write:
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):
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.The text was updated successfully, but these errors were encountered: