os_str_bytes/common/
mod.rs
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 = "hermit")]
10use std::os::hermit as os;
11#[cfg(target_os = "solid_asp3")]
12use std::os::solid as os;
13#[cfg(unix)]
14use std::os::unix as os;
15#[cfg(target_os = "wasi")]
16use std::os::wasi as os;
17#[cfg(target_os = "xous")]
18use std::os::xous as os;
19
20use os::ffi::OsStrExt;
21use os::ffi::OsStringExt;
22
23if_raw_str! {
24 pub(super) mod raw;
25}
26
27pub(super) type EncodingError = Infallible;
28
29pub(super) type Result<T> = result::Result<T, EncodingError>;
30
31pub(super) fn os_str_from_bytes(string: &[u8]) -> Result<Cow<'_, OsStr>> {
32 Ok(Cow::Borrowed(OsStrExt::from_bytes(string)))
33}
34
35pub(super) fn os_str_to_bytes(os_string: &OsStr) -> Cow<'_, [u8]> {
36 Cow::Borrowed(OsStrExt::as_bytes(os_string))
37}
38
39pub(super) fn os_string_from_vec(string: Vec<u8>) -> Result<OsString> {
40 Ok(OsStringExt::from_vec(string))
41}
42
43pub(super) fn os_string_into_vec(os_string: OsString) -> Vec<u8> {
44 OsStringExt::into_vec(os_string)
45}