1 use std::borrow::Cow; 2 use std::convert::Infallible; 3 use std::ffi::OsStr; 4 use std::ffi::OsString; 5 use std::result; 6 7 #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] 8 use std::os::fortanix_sgx as os; 9 #[cfg(target_os = "solid_asp3")] 10 use std::os::solid as os; 11 #[cfg(any(target_os = "hermit", unix))] 12 use std::os::unix as os; 13 #[cfg(target_os = "wasi")] 14 use std::os::wasi as os; 15 #[cfg(target_os = "xous")] 16 use std::os::xous as os; 17 18 use os::ffi::OsStrExt; 19 use os::ffi::OsStringExt; 20 21 if_raw_str! { 22 pub(super) mod raw; 23 } 24 25 pub(super) type EncodingError = Infallible; 26 27 type Result<T> = result::Result<T, EncodingError>; 28 os_str_from_bytes(string: &[u8]) -> Result<Cow<'_, OsStr>>29pub(super) fn os_str_from_bytes(string: &[u8]) -> Result<Cow<'_, OsStr>> { 30 Ok(Cow::Borrowed(OsStrExt::from_bytes(string))) 31 } 32 os_str_to_bytes(os_string: &OsStr) -> Cow<'_, [u8]>33pub(super) fn os_str_to_bytes(os_string: &OsStr) -> Cow<'_, [u8]> { 34 Cow::Borrowed(OsStrExt::as_bytes(os_string)) 35 } 36 os_string_from_vec(string: Vec<u8>) -> Result<OsString>37pub(super) fn os_string_from_vec(string: Vec<u8>) -> Result<OsString> { 38 Ok(OsStringExt::from_vec(string)) 39 } 40 os_string_into_vec(os_string: OsString) -> Vec<u8>41pub(super) fn os_string_into_vec(os_string: OsString) -> Vec<u8> { 42 OsStringExt::into_vec(os_string) 43 } 44