Type Definition widestring::U16CString [−][src]
type U16CString = UCString<u16>;
An owned, mutable C-style “wide” string for FFI that is nul-aware and nul-terminated.
U16CString
is aware of nul values. Unless unchecked conversions are used, all U16CString
strings end with a nul-terminator in the underlying buffer and contain no internal nul values.
The strings may still contain invalid or ill-formed UTF-16 data. These strings are intended to
be used with FFI functions such as Windows API that may require nul-terminated strings.
U16CString
can be converted to and from many other string types, including U16String
,
OsString
, and String
, making proper Unicode FFI safe and easy.
Examples
The following example constructs a U16CString
and shows how to convert a U16CString
to a
regular Rust String
.
use widestring::U16CString; let s = "Test"; // Create a wide string from the rust string let wstr = U16CString::from_str(s).unwrap(); // Convert back to a rust string let rust_str = wstr.to_string_lossy(); assert_eq!(rust_str, "Test");