use std::borrow::Cow;
use std::path::{Path, PathBuf};
pub(crate) fn path_bytes(path: &Path) -> Cow<'_, [u8]> {
#[cfg(unix)]
{
use std::os::unix::ffi::OsStrExt;
Cow::Borrowed(path.as_os_str().as_bytes())
}
#[cfg(not(unix))]
{
Cow::Owned(path.to_string_lossy().into_owned().into_bytes())
}
}
pub(crate) fn path_from_bytes(bytes: &[u8]) -> PathBuf {
#[cfg(unix)]
{
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;
PathBuf::from(OsString::from_vec(bytes.to_vec()))
}
#[cfg(not(unix))]
{
PathBuf::from(String::from_utf8_lossy(bytes).into_owned())
}
}