Skip to content
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

No equivalent of into_boxed_str for CString/CStr #40248

Closed
jonhoo opened this issue Mar 3, 2017 · 2 comments
Closed

No equivalent of into_boxed_str for CString/CStr #40248

jonhoo opened this issue Mar 3, 2017 · 2 comments

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Mar 3, 2017

I'm working on implementing serde::Deserialize for CStr (in serde-rs/serde#801), and am running into the need for an equivalent of String::into_boxed_str for CString/CStr. With the current internals for CStr, I believe the implementation could be very similar; namely:

pub fn into_boxed_cstr(self) -> Box<CStr> {
    unsafe { mem::transmute::<Box<[u8]>, Box<CStr>>(self.inner) }
}

Is this something that could be added in line with #18283 ?

jonhoo added a commit to jonhoo/serde that referenced this issue Mar 3, 2017
@alexcrichton
Copy link
Member

I think this was added in #39594, but can you confirm that the one you're looking for was there?

@jonhoo
Copy link
Contributor Author

jonhoo commented Mar 4, 2017

Ah, yes, that looks perfect! Thanks.

@jonhoo jonhoo closed this as completed Mar 4, 2017
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

No branches or pull requests

2 participants