-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Owned conversions for CString #28977
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
/// | ||
/// On failure, ownership of the original `CString` is returned. | ||
#[unstable(feature = "convert", reason = "recently added", issue = "27704")] | ||
pub fn into_string(self) -> Result<String, CString> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike OsString
's into_string
method this actually has some extra contextual information to give back (e.g. the str::Utf8Error
). Along those lines this may want to return its own custom error type (e.g. the same as FromUtf8Error
but with a CString
instead of String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you suggest what this type should be called? Would the best course of action be to just create std::ffi::FromUtf8Error
or name it CStringFromUtf8Error
or..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably be called IntoStringError
Thanks @arcnmx! These look pretty good to me, but gonna tag with |
We chatted about this in the libs team meeting today and were fine moving forward with it. We also thought that it would be a good idea to hold off on an |
Included the requested comment and created an |
/// Consumes this error, returning original `CString` which generated the | ||
/// error. | ||
#[unstable(feature = "convert", reason = "recently added", issue = "0")] | ||
pub fn into_inner(self) -> CString { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this instead be called into_cstring
? There's some precedent here (NulError::into_vec
and FromUtf8Error::into_bytes
) but they're not even consistent so I wasn't sure...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's call this into_cstring
for now to stick with into_<type>
of the other errors.
/// An error returned from `CString::into_string` to indicate that a UTF-8 error | ||
/// was encountered during the conversion. | ||
#[derive(Clone, PartialEq, Debug)] | ||
#[unstable(feature = "convert", reason = "recently added", issue = "0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created #29157 to connect all these features, to, so could you connect them via issue
to that and then also update the feature name here to something like cstring_into
or something similar?
Changes made! |
Looks good to me! Could you also squash down to one commit? Other than that r=me |
Squashed! |
`OsString` has these sorts of conversions, while `CString` has been missing them. I'm iffy on `into_string` simply because the return type would be better off as `FromUtf8Error<CString>`, which of course isn't generic 😢 Also should a different/new feature gate be used?
OsString
has these sorts of conversions, whileCString
has been missing them. I'm iffy oninto_string
simply because the return type would be better off asFromUtf8Error<CString>
, which of course isn't generic 😢Also should a different/new feature gate be used?