widestring 1.1.0

A wide string Rust library for converting to and from wide strings, such as those often used in Windows API or other FFI libaries. Both `u16` and `u32` string types are provided, including support for UTF-16 and UTF-32, malformed encoding, C-style strings, etc.
Documentation
1
2
3
4
5
6
7
8
9
use std::ffi::{OsStr, OsString};

pub(crate) fn os_to_wide(s: &OsStr) -> Vec<u16> {
    s.to_string_lossy().encode_utf16().collect()
}

pub(crate) fn os_from_wide(s: &[u16]) -> OsString {
    OsString::from(String::from_utf16_lossy(s))
}