1 //! Redox-specific extension to the primitives in the `std::ffi` module.
3 #![stable(feature = "rust1", since = "1.0.0")]
5 use crate::ffi::{OsStr, OsString};
7 use crate::sys::os_str::Buf;
8 use crate::sys_common::{FromInner, IntoInner, AsInner};
10 /// Redox-specific extensions to [`OsString`].
12 /// [`OsString`]: ../../../../std/ffi/struct.OsString.html
13 #[stable(feature = "rust1", since = "1.0.0")]
14 pub trait OsStringExt {
15 /// Creates an `OsString` from a byte vector.
16 #[stable(feature = "rust1", since = "1.0.0")]
17 fn from_vec(vec: Vec<u8>) -> Self;
19 /// Yields the underlying byte vector of this `OsString`.
20 #[stable(feature = "rust1", since = "1.0.0")]
21 fn into_vec(self) -> Vec<u8>;
24 #[stable(feature = "rust1", since = "1.0.0")]
25 impl OsStringExt for OsString {
26 fn from_vec(vec: Vec<u8>) -> OsString {
27 FromInner::from_inner(Buf { inner: vec })
29 fn into_vec(self) -> Vec<u8> {
30 self.into_inner().inner
34 /// Redox-specific extensions to [`OsStr`].
36 /// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html
37 #[stable(feature = "rust1", since = "1.0.0")]
39 #[stable(feature = "rust1", since = "1.0.0")]
40 fn from_bytes(slice: &[u8]) -> &Self;
42 /// Gets the underlying byte view of the `OsStr` slice.
43 #[stable(feature = "rust1", since = "1.0.0")]
44 fn as_bytes(&self) -> &[u8];
47 #[stable(feature = "rust1", since = "1.0.0")]
48 impl OsStrExt for OsStr {
49 fn from_bytes(slice: &[u8]) -> &OsStr {
50 unsafe { mem::transmute(slice) }
52 fn as_bytes(&self) -> &[u8] {
53 &self.as_inner().inner