Open kornelski opened 4 years ago
There is already .into_string()
I would love to know why this isn't deprecated and TryInto
cstring.into_string
is a conversion in the opposite direction than what I had in mind, but I wouldn't mind if both were supported via TryFrom
/TryInto
.
Higher-level FFI wrappers that need to present a
CString
to C don't have a convenient + efficient type to take on the Rust side.Taking
CString
is cumbersome, as it doesn't work with simple&str
and requires callers to do the conversion and handle NUL errors.Taking
String
orVec<u8>
is efficient only if it happens to have spare capacity, but"foo".to_string()
doesn't have any spare capacity.Taking
&str
always needs to allocate.Taking
impl TryInto<CString>
would be ideal, if that trait was implemented for common string-like types.