Skip to main content

stable_osstring_encoding/
impl_unix_wasi.rs

1use crate::{EncodingWidth, FromRawStableEncoding, IntoRawStableEncoding, ToRawStableEncoding};
2use std::{
3	borrow::Cow,
4	ffi::{OsStr, OsString},
5};
6
7#[cfg(unix)]
8use std::os::unix::ffi::{OsStrExt, OsStringExt};
9#[cfg(target_os = "wasi")]
10use std::os::wasi::ffi::{OsStrExt, OsStringExt}; // this is just a re-export of the unix version
11
12
13
14impl ToRawStableEncoding for OsStr {
15	#[inline]
16	fn to_raw_stable_encoding(&self) -> Vec<EncodingWidth> {
17		self.as_bytes().to_vec()
18	}
19}
20
21impl IntoRawStableEncoding for OsString {
22	#[inline]
23	fn into_raw_stable_encoding(self) -> Vec<EncodingWidth> {
24		self.into_vec()
25	}
26}
27
28impl FromRawStableEncoding for OsString {
29	#[inline]
30	unsafe fn from_raw_stable_encoding<'a>(encoded: impl Into<Cow<'a, [EncodingWidth]>>) -> Self {
31		Self::from_vec(encoded.into().into_owned())
32	}
33}