use std::ffi::OsStr;
use std::mem;
use crate::ext;
use super::OsUnits;
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd)]
pub struct OsUnit(pub(crate) u16);
impl OsUnit {
#[inline]
#[must_use]
pub fn to_u64(&self) -> u64 {
self.0.into()
}
}
impl From<OsUnit> for u64 {
#[inline]
fn from(value: OsUnit) -> Self {
value.to_u64()
}
}
#[derive(Debug, Hash, PartialEq, PartialOrd)]
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "raw_os_str")))]
#[repr(transparent)]
pub struct NonUnicodeOsStr(OsStr);
impl NonUnicodeOsStr {
unsafe fn from_inner(string: &OsStr) -> &Self {
unsafe { mem::transmute(string) }
}
pub(super) unsafe fn new_unchecked(string: &[u8]) -> &Self {
unsafe { Self::from_inner(ext::os_str(string)) }
}
#[inline]
#[must_use]
pub fn as_os_str(&self) -> &OsStr {
&self.0
}
#[inline]
pub fn os_units(&self) -> OsUnits<'_> {
OsUnits::new(self)
}
}
impl AsRef<OsStr> for NonUnicodeOsStr {
#[inline]
fn as_ref(&self) -> &OsStr {
&self.0
}
}