use core::cmp::Ordering;
use core::fmt::{self, Debug, Display, Formatter};
use core::hash::{Hash, Hasher};
use core::ops::{Deref, DerefMut};
use widestring::Utf16Str as WideUtf16Str;
#[repr(transparent)]
pub struct Utf16Str([u16]);
unsafe impl ptr_meta::Pointee for Utf16Str {
type Metadata = usize;
}
impl Utf16Str {
#[inline]
#[must_use]
pub fn as_widestring_utf16_str(&self) -> &widestring::Utf16Str {
unsafe { WideUtf16Str::from_slice_unchecked(&self.0) }
}
#[inline]
#[must_use]
pub fn as_mut_widestring_utf16_str(&mut self) -> &mut widestring::Utf16Str {
unsafe { WideUtf16Str::from_slice_unchecked_mut(&mut self.0) }
}
}
impl Deref for Utf16Str {
type Target = WideUtf16Str;
#[inline]
fn deref(&self) -> &WideUtf16Str {
self.as_widestring_utf16_str()
}
}
impl DerefMut for Utf16Str {
#[inline]
fn deref_mut(&mut self) -> &mut WideUtf16Str {
self.as_mut_widestring_utf16_str()
}
}
impl Debug for Utf16Str {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Debug::fmt(self.as_widestring_utf16_str(), f)
}
}
impl Display for Utf16Str {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(self.as_widestring_utf16_str(), f)
}
}
impl PartialEq for Utf16Str {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl Eq for Utf16Str {}
impl PartialOrd for Utf16Str {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Utf16Str {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}
impl Hash for Utf16Str {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl PartialEq<WideUtf16Str> for Utf16Str {
#[inline]
fn eq(&self, other: &WideUtf16Str) -> bool {
self.as_widestring_utf16_str() == other
}
}