use std::ffi::{OsStr, OsString};
use std::os::windows::ffi::{OsStrExt, OsStringExt};
use super::{Wtf16Str, Wtf16String};
impl Wtf16String {
#[must_use]
pub fn from_os_str(s: &OsStr) -> Self {
Self::from_encoded(s.encode_wide().collect())
}
#[must_use]
pub fn from_wide(units: &[u16]) -> Self {
Self::from_units(units)
}
}
impl Wtf16Str {
#[must_use]
pub fn to_os_string(&self) -> OsString {
OsString::from_wide(self.as_units())
}
pub fn encode_wide(&self) -> impl Iterator<Item = u16> + '_ {
self.as_units().iter().copied()
}
}
impl From<&OsStr> for Wtf16String {
fn from(s: &OsStr) -> Self {
Self::from_os_str(s)
}
}
impl From<&OsString> for Wtf16String {
fn from(s: &OsString) -> Self {
Self::from_os_str(s)
}
}
impl From<OsString> for Wtf16String {
fn from(s: OsString) -> Self {
Self::from_os_str(&s)
}
}
impl From<&Wtf16Str> for OsString {
fn from(s: &Wtf16Str) -> Self {
s.to_os_string()
}
}
impl From<&Wtf16String> for OsString {
fn from(s: &Wtf16String) -> Self {
s.to_os_string()
}
}
impl From<Wtf16String> for OsString {
fn from(s: Wtf16String) -> Self {
s.to_os_string()
}
}
#[cfg(test)]
mod tests;