use std::ffi::OsStr;
use crate::traits::StringToFromBytes;
impl StringToFromBytes for OsStr {
#[cfg(all(
feature = "safe",
not(feature = "win_min_unsafe"),
target_family = "windows"
))]
#[inline]
fn bytes_as_self(bytes: &[u8]) -> &Self {
compile_error!(
"OsStr/Path support is not available with the 'safe' feature on Windows. Using the 'win_min_unsafe' feature in combination with 'safe' will allow it to compile, but will use a single unsafe call."
);
unreachable!()
}
#[cfg(all(feature = "safe", target_family = "unix"))]
#[inline]
fn bytes_as_self(bytes: &[u8]) -> &Self {
use std::os::unix::prelude::OsStrExt;
OsStrExt::from_bytes(bytes)
}
#[cfg(all(feature = "safe", target_os = "wasi"))]
#[inline]
fn bytes_as_self(bytes: &[u8]) -> &Self {
use std::os::wasi::prelude::OsStrExt;
OsStrExt::from_bytes(bytes)
}
#[cfg(any(
not(feature = "safe"),
all(feature = "win_min_unsafe", target_family = "windows")
))]
#[inline]
fn bytes_as_self(bytes: &[u8]) -> &Self {
unsafe { OsStr::from_encoded_bytes_unchecked(bytes) }
}
#[inline]
fn self_as_raw_bytes(&self) -> &[u8] {
self.as_encoded_bytes()
}
}