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