-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add u8::to_ascii_digit() #95969
Comments
@rustbot claim |
#96110 should fix this. |
I'm not sure it's a good idea, this could make people confuse what is what. A u8 is not supposed to be a character, std force the user to convert a u8 to char is a nice way to prevent mistake. IMO the first sniped is more explicit than the second |
Can you elaborate on this part please? I couldn't really get what you mean @Stargateur |
I think there's good intuitive symmetry with the other ascii* functions already on u8. With the provided snippets I find both equally explicit, but I think having this method goes well with the other ascii methods already available, and is equally explicit in general. |
The existing methods |
I commented on #96110:
|
As indicated on the issue templates, it's usually best to discuss feature requests on https://internals.rust-lang.org/ rather than opening an issue for them. |
Proposal to close this since the PR has been closed? [See PR thread for discussion] |
In #96110 (comment) there are several reasons this should probably be closed. Further work on this (perhaps in the form of a more fleshed out |
(Ah, my bad, thanks) |
When writing parsers for textual or semi-textual data received from an external source, one often gets octets that need to be interpreted as decimal numbers. For example:
While the compiler might be able to optimize this code sufficiently, a function like
u8::to_ascii_digit()
would allow us to operate onu8
directly, making the meaning clearer. It would be analogous to the already existingis_ascii_digit()
andto_ascii_{lower,upper}case()
. In the case of the above code, it would look like this:The advantage is that it's clear we're working on octets the whole time. It avoids the cast to
char
which made the code look like it handled non-ASCII characters, when it in reality didn't, nor was it supposed to.The text was updated successfully, but these errors were encountered: