Currently, wstr_to_string unwraps from a string conversion which is not good. Its cstr equivalent raises an error.
However, a naive attempt to just make wstr_to_string as similar to cstr_to_string by making it:
unsafe fn wwstr_to_string(ptr: *const libc::c_char) -> Result<Option<String>, Error> {
let string = if ptr.is_null() {
None
} else {
Some(WideCString::from_ptr_str(ptr as _).to_string()?.to_owned())
};
Ok(string)
}
runs into the probelm that to_string above returns FromUtf16Error. Therefore, one also need to correctly convert it into the existing Error enum. There are a few options, but none of them are very exciting:
add a new enum to the list - this is not back-compatible (can just save this change for a 0.9 though)
change the value of MalformedError to be an enum that contains either a UTF-8 or UTF-16 error. This, i also do not think is back-compatible. Furthermore the UTF-8 error is Utf8Error and the UTF-16 error is FromUtf16Error which is annoying for its lack of consistency. There is no Utf16Error and one cannot get FromUtf8Error from Utf8Error.
Currently,
wstr_to_string
unwraps from a string conversion which is not good. Itscstr
equivalent raises an error.However, a naive attempt to just make
wstr_to_string
as similar tocstr_to_string
by making it:runs into the probelm that
to_string
above returnsFromUtf16Error
. Therefore, one also need to correctly convert it into the existingError
enum. There are a few options, but none of them are very exciting:MalformedError
to be an enum that contains either a UTF-8 or UTF-16 error. This, i also do not think is back-compatible. Furthermore the UTF-8 error isUtf8Error
and the UTF-16 error isFromUtf16Error
which is annoying for its lack of consistency. There is noUtf16Error
and one cannot getFromUtf8Error
fromUtf8Error
.