-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
core: implement Add and AddAssign for ascii::Char #120219
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
@scottmcm, this is the Add implementation I’ve suggested a while ago. It obsoletes digit and digit_unchecked so I think those methods can be removed. Alas, the issue is that I cannot figure out tests. I was expected debug_assertions to be defined and thus the two overflowing tests to panic alas that doesn’t happen. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Tagging this for some libs-api eyes, since I think this is the first For example, https://doc.rust-lang.org/nightly/std/num/struct.NonZeroU32.html doesn't implement (I'm also personally a bit skeptical how often |
NonZero types have special add functions because it must not have 0. |
We discussed this in today's @rust-lang/libs-api meeting. We're still vigorously debating the merits of the However, we all agreed that we want the So, could you please:
|
There is a difference between char, NonZero and AsciiChar in regards to Add. AsciiChar can be thought of as
#120311. I also took the liberty of dropping to_u8 and to_char in that PR as well as adding conversion to all other unsigned integers. I’m not fundamentally opposed to those methods but char doesn’t have them so such change matches API that char has. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Remaining issue is with some snapshot tests which I’m not clear how to update. Since this is draft and under discussion whether it’s going to be accepted I’m leaving it for now. |
I'm clearing this from my queue while it's in draft, but you can use @rustbot author |
This comment has been minimized.
This comment has been minimized.
Implement Add and AddAsign for core::ascii::Char treating it as if it was a 7-bit unsigned type, i.e. in debug builds overflow panics and in release seven least significant bits of the result are taken. The operators can be used to convert an integer into a digit or a letter of an alphabet: use core::ascii::Char; assert_eq!(Char::Digit8, Char::Digit0 + 8); assert_eq!(Char::SmallI, Char::SmallA + 8); Issue: rust-lang#110998
@rustbot ready I guess it’s up to you guys now to decide whether you want it or not. IMO it does make sense due to reasons outlined in earlier comment. |
r? libs-api |
Note for reviewers, there's some community debate for this starting in #110998 (comment) |
We discussed this in the libs-api meeting today. The team was somewhat split on this issue, but ultimately we decided not to accept this change. The primary reason is that addition is not a concept that really make sense on characters: we would prefer that code use |
To clarify, not everyone had objections to this change, but additions like these require team consensus, which cannot be reached when several people have objections. For me personally, my objections are:
|
Implement Add and AddAssign for ascii::Char which panics in debug
builds if sum isn’t an ASCII character and wraps the result in release
builds. The operators can be used to convert an integer into a digit
or a letter of an alphabet:
Issue: #110998