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	fn to_raw_stable_encoding(&self) -> Vec<EncodingWidth> {
16		self.as_bytes().to_vec()
17	}
18}
19
20impl IntoRawStableEncoding for OsString {
21	fn into_raw_stable_encoding(self) -> Vec<EncodingWidth> {
22		self.into_vec()
23	}
24}
25
26impl FromRawStableEncoding for OsString {
27	unsafe fn from_raw_stable_encoding<'a>(encoded: impl Into<Cow<'a, [EncodingWidth]>>) -> Self {
28		Self::from_vec(encoded.into().into_owned())
29	}
30}