std/os/unix/ffi/
os_str.rs1use crate::ffi::{OsStr, OsString};
2use crate::mem;
3use crate::sys::os_str::Buf;
4use crate::sys::{AsInner, FromInner, IntoInner};
5
6#[stable(feature = "rust1", since = "1.0.0")]
11pub impl(self) trait OsStringExt {
12 #[stable(feature = "rust1", since = "1.0.0")]
16 fn from_vec(vec: Vec<u8>) -> Self;
17
18 #[stable(feature = "rust1", since = "1.0.0")]
22 fn into_vec(self) -> Vec<u8>;
23}
24
25#[stable(feature = "rust1", since = "1.0.0")]
26impl OsStringExt for OsString {
27 #[inline]
28 fn from_vec(vec: Vec<u8>) -> OsString {
29 FromInner::from_inner(Buf { inner: vec })
30 }
31 #[inline]
32 fn into_vec(self) -> Vec<u8> {
33 self.into_inner().inner
34 }
35}
36
37#[stable(feature = "rust1", since = "1.0.0")]
39pub impl(self) trait OsStrExt {
40 #[stable(feature = "rust1", since = "1.0.0")]
41 fn from_bytes(slice: &[u8]) -> &Self;
45
46 #[stable(feature = "rust1", since = "1.0.0")]
50 fn as_bytes(&self) -> &[u8];
51}
52
53#[stable(feature = "rust1", since = "1.0.0")]
54impl OsStrExt for OsStr {
55 #[inline]
56 fn from_bytes(slice: &[u8]) -> &OsStr {
57 unsafe { mem::transmute(slice) }
58 }
59 #[inline]
60 fn as_bytes(&self) -> &[u8] {
61 &self.as_inner().inner
62 }
63}