1use super::{RawStr, RawString};
4use std::ffi::{OsStr, OsString};
5use std::os::unix::ffi::{OsStrExt, OsStringExt};
6use std::path::{Path, PathBuf};
7
8pub trait RawStrExt {
9 fn as_osstr(&self) -> &OsStr;
10 fn as_path(&self) -> &Path;
11}
12
13pub trait RawStringExt {
14 fn into_osstring(self) -> OsString;
15 fn into_pathbuf(self) -> PathBuf;
16}
17
18impl RawStrExt for RawStr {
20 #[inline]
21 fn as_osstr(&self) -> &OsStr {
22 OsStr::from_bytes(self.as_bytes())
23 }
24 #[inline]
25 fn as_path(&self) -> &Path {
26 Path::new(self.as_osstr())
27 }
28}
29
30impl RawStringExt for RawString {
32 #[inline]
33 fn into_osstring(self) -> OsString {
34 OsString::from_vec(self.into_bytes())
35 }
36 #[inline]
37 fn into_pathbuf(self) -> PathBuf {
38 PathBuf::from(self.into_osstring())
39 }
40}