use crate::{EncodingWidth, FromRawStableEncoding, IntoRawStableEncoding, ToRawStableEncoding};
use std::{
borrow::Cow,
ffi::{OsStr, OsString},
};
#[cfg(unix)]
use std::os::unix::ffi::{OsStrExt, OsStringExt};
#[cfg(target_os = "wasi")]
use std::os::wasi::ffi::{OsStrExt, OsStringExt};
impl ToRawStableEncoding for OsStr {
#[inline]
fn to_raw_stable_encoding(&self) -> Vec<EncodingWidth> {
self.as_bytes().to_vec()
}
}
impl IntoRawStableEncoding for OsString {
#[inline]
fn into_raw_stable_encoding(self) -> Vec<EncodingWidth> {
self.into_vec()
}
}
impl FromRawStableEncoding for OsString {
#[inline]
unsafe fn from_raw_stable_encoding<'a>(encoded: impl Into<Cow<'a, [EncodingWidth]>>) -> Self {
Self::from_vec(encoded.into().into_owned())
}
}