-
Notifications
You must be signed in to change notification settings - Fork 20
ACP: impl TryFrom<char> for u16
#146
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
My instinct is that this is too uncommon and situational to be a trait impl. I don't know that we want anything in traits that's UCS-2, since I don't think we even have UTF-16 in traits. Overall, it just doesn't seem so bad to do -let ucs2 = ch.try_into().map_err(|_| Error)?;
+let ucs2 = u32::from(ch).try_into().map_err(|_| Error)?; so it's hard to pass the "we can't experiment with it because it's insta-stable" bar. Is there a version of this that could be a method instead? The bar for |
We discussed this in the libs-api meeting just now. There was some discussion on whether this would wrongly be used in situations where utf-16 should be used instead, but we mostly felt positive about the conversion. We didn't reach full consensus yet, but this change would be insta-stable (since it's a trait implementation), so can you send a PR to rust-lang/rust for this? Then we can propose an FCP and see if we can get consensus on it. Thanks! |
`impl TryFrom<char> for u16` This PR implements the final missing `char` -> unsigned integer conversion. ACP: rust-lang/libs-team#146 r? libs-api `@rustbot` label +T-libs-api +needs-fcp -T-libs
`impl TryFrom<char> for u16` This PR implements the final missing `char` -> unsigned integer conversion. ACP: rust-lang/libs-team#146 r? libs-api `@rustbot` label +T-libs-api +needs-fcp -T-libs
`impl TryFrom<char> for u16` This PR implements the final missing `char` -> unsigned integer conversion. ACP: rust-lang/libs-team#146 r? libs-api `@rustbot` label +T-libs-api +needs-fcp -T-libs
`impl TryFrom<char> for u16` This PR implements the final missing `char` -> unsigned integer conversion. ACP: rust-lang/libs-team#146 r? libs-api `@rustbot` label +T-libs-api +needs-fcp -T-libs
Proposal
Problem statement
Implement
TryFrom<char> for u16
, similar to the existingTryFrom<char> for u8
.Motivation, use-cases
I have project, which (unfortunately) has to deal with UCS-2 encoded strings (UCS-2 is like UTF-16, but no surrogates). I am currently in the process of replacing
as
casts with safer alternatives and found that this impl was missing.One example of using this feature for collecting an iterator of chars into a preallocated UCS-2 string: (playground)
Solution sketches
Copy-paste the impl from
u8
, but replaceu8
withu16
:Links and related work
impl TryFrom<char> for u8
: ImplementTryFrom<char>
foru8
rust#84640What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: