use super::*;
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct PWSTR(pub *mut u16);
impl PWSTR {
pub const fn from_raw(ptr: *mut u16) -> Self {
Self(ptr)
}
pub fn null() -> Self {
Self(std::ptr::null_mut())
}
pub fn as_ptr(&self) -> *mut u16 {
self.0
}
pub fn is_null(&self) -> bool {
self.0.is_null()
}
pub unsafe fn as_wide(&self) -> &[u16] {
let len = super::wcslen(PCWSTR::from_raw(self.0));
std::slice::from_raw_parts(self.0, len)
}
pub unsafe fn to_string(&self) -> std::result::Result<String, std::string::FromUtf16Error> {
String::from_utf16(self.as_wide())
}
pub unsafe fn to_hstring(&self) -> Result<HSTRING> {
HSTRING::from_wide(self.as_wide())
}
pub unsafe fn display(&self) -> impl std::fmt::Display + '_ {
Decode(move || std::char::decode_utf16(self.as_wide().iter().cloned()))
}
}
impl TypeKind for PWSTR {
type TypeKind = CopyType;
}