Skip to content

No equivalent of into_boxed_str for CString/CStr #40248

Closed
@jonhoo

Description

@jonhoo

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions