1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Unix-specific extension to the primitives in the `std::ffi` module
13 #![stable(feature = "rust1", since = "1.0.0")]
15 use ffi::{OsStr, OsString};
18 use sys_common::{FromInner, IntoInner, AsInner};
20 /// Unix-specific extensions to `OsString`.
21 #[stable(feature = "rust1", since = "1.0.0")]
22 pub trait OsStringExt {
23 /// Creates an `OsString` from a byte vector.
24 #[stable(feature = "rust1", since = "1.0.0")]
25 fn from_vec(vec: Vec<u8>) -> Self;
27 /// Yields the underlying byte vector of this `OsString`.
28 #[stable(feature = "rust1", since = "1.0.0")]
29 fn into_vec(self) -> Vec<u8>;
32 #[stable(feature = "rust1", since = "1.0.0")]
33 impl OsStringExt for OsString {
34 fn from_vec(vec: Vec<u8>) -> OsString {
35 FromInner::from_inner(Buf { inner: vec })
37 fn into_vec(self) -> Vec<u8> {
38 self.into_inner().inner
42 /// Unix-specific extensions to `OsStr`.
43 #[stable(feature = "rust1", since = "1.0.0")]
45 #[stable(feature = "rust1", since = "1.0.0")]
46 fn from_bytes(slice: &[u8]) -> &Self;
48 /// Gets the underlying byte view of the `OsStr` slice.
49 #[stable(feature = "rust1", since = "1.0.0")]
50 fn as_bytes(&self) -> &[u8];
53 #[stable(feature = "rust1", since = "1.0.0")]
54 impl OsStrExt for OsStr {
55 fn from_bytes(slice: &[u8]) -> &OsStr {
56 unsafe { mem::transmute(slice) }
58 fn as_bytes(&self) -> &[u8] {
59 &self.as_inner().inner