use std::ops::Deref;
use widestring::U16CString;
use windows::core::PCWSTR;
use windows::core::Param;
#[derive(Debug)]
pub struct PCWSTRGuard {
string: U16CString,
}
impl PCWSTRGuard {
pub fn new(string: U16CString) -> Self {
Self { string }
}
pub unsafe fn as_ptr(&self) -> PCWSTR {
PCWSTR(self.string.as_ptr())
}
pub fn as_wide(&self) -> &[u16] {
self.string.as_slice()
}
}
impl Deref for PCWSTRGuard {
type Target = U16CString;
fn deref(&self) -> &Self::Target {
&self.string
}
}
impl Param<PCWSTR> for &PCWSTRGuard {
unsafe fn param(self) -> windows::core::ParamValue<PCWSTR> {
windows::core::ParamValue::Borrowed(PCWSTR(self.string.as_ptr()))
}
}
impl AsRef<PCWSTRGuard> for PCWSTRGuard {
fn as_ref(&self) -> &PCWSTRGuard {
self
}
}