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