use windows::core::HSTRING as WindowsHString;
use std::fmt;
#[derive(Clone)]
pub struct HString {
inner: WindowsHString,
}
impl HString {
pub fn from(s: impl AsRef<str>) -> Self {
HString {
inner: WindowsHString::from(s.as_ref()),
}
}
pub fn new() -> Self {
HString {
inner: WindowsHString::new(),
}
}
pub fn as_ptr(&self) -> *const u16 {
self.inner.as_ptr()
}
pub fn len(&self) -> usize {
self.inner.len()
}
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
pub fn to_string_lossy(&self) -> String {
self.inner.to_string_lossy()
}
pub fn inner(&self) -> &WindowsHString {
&self.inner
}
}
impl Default for HString {
fn default() -> Self {
Self::new()
}
}
impl fmt::Debug for HString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HString(\"{}\")", self.to_string_lossy())
}
}
impl fmt::Display for HString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_string_lossy())
}
}
impl From<&str> for HString {
fn from(s: &str) -> Self {
HString::from(s)
}
}
impl From<String> for HString {
fn from(s: String) -> Self {
HString::from(s.as_str())
}
}