use windows::core::PCWSTR;
pub struct PCWSTRWrapper(Vec<u16>);
impl PCWSTRWrapper {
pub unsafe fn as_pcwstr(&self) -> PCWSTR {
PCWSTR::from_raw(self.0.as_ptr())
}
fn new<T: AsRef<str>>(text: T) -> Self {
let text = text.as_ref();
let mut text = text.encode_utf16().collect::<Vec<_>>();
text.push(0);
Self(text)
}
}
pub(crate) trait ToPCWSTRWrapper {
fn to_pcwstr(&self) -> PCWSTRWrapper;
}
impl ToPCWSTRWrapper for &str {
fn to_pcwstr(&self) -> PCWSTRWrapper {
PCWSTRWrapper::new(self)
}
}
impl ToPCWSTRWrapper for String {
fn to_pcwstr(&self) -> PCWSTRWrapper {
PCWSTRWrapper::new(self)
}
}