Skip to content

std: Add trait ToCU16Str #14242

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

Closed
wants to merge 2 commits into from
Closed

std: Add trait ToCU16Str #14242

wants to merge 2 commits into from

Conversation

klutzy
Copy link
Contributor

@klutzy klutzy commented May 16, 2014

First patch adds ToCU16Str for UTF-16 ffi.
It also removes std::os::win32::{as_utf16_p, as_mut_utf16_p}.

Second patch changes return type of from_utf16{,_lossy} to StrBuf.

[breaking-change]

klutzy added 2 commits May 16, 2014 13:25
`ToCU16Str` has `to_c_u16_str` method which converts receiver into
null-terminated UTF-16 vector (like `ToCStr::to_c_str`).
It also has `with_c_u16_str` method like `ToCStr::with_c_str`.

This patch also removes `std::os::win32::{as_utf16_p, as_mut_utf16_p}`.

[breaking-change]
@alexcrichton
Copy link
Member

How common is utf16 c strings outside of windows api compatibility? I thought that it was quite rare, which would make me think that a trait in the c_str module doesn't quite fit. If we do go with this, I find it odd that to_c_str() returns a CString and to_c_utf16_str() returns Vec<u16>. I think that Vec<u16> is an ok type to use, and I like that it uses RAII and not closures, but this seems like it may just want to change as_utf16_p in the win32 module to just returning a Vec<u16>.

@klutzy
Copy link
Contributor Author

klutzy commented May 22, 2014

Hmm, the patch doesn't seem necessary as I initially thought - I thought as_utf16_p should be renamed to with_utf16_p and it'd be better if it is available regardless of OS (so added a trait at c_str).
But I now think there's too small usage of the trait outside of windows, while (re-)implementing as_utf16_p is still easy for such cases.

@klutzy klutzy closed this May 22, 2014
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 20, 2025
…st-lang#14243)

fix rust-lang#14242

changelog: [`unnecessary_to_owned`]: don't call `iter` on a temporary
object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants