]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/ext/ffi.rs
add -Z pre-link-arg{,s} to rustc
[rust.git] / src / libstd / sys / windows / ext / ffi.rs
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.
4 //
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.
10
11 //! Windows-specific extensions to the primitives in the `std::ffi` module.
12
13 #![stable(feature = "rust1", since = "1.0.0")]
14
15 use ffi::{OsString, OsStr};
16 use sys::os_str::Buf;
17 use sys_common::wtf8::Wtf8Buf;
18 use sys_common::{FromInner, AsInner};
19
20 #[stable(feature = "rust1", since = "1.0.0")]
21 pub use sys_common::wtf8::EncodeWide;
22
23 /// Windows-specific extensions to `OsString`.
24 #[stable(feature = "rust1", since = "1.0.0")]
25 pub trait OsStringExt {
26     /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of
27     /// 16-bit code units.
28     ///
29     /// This is lossless: calling `.encode_wide()` on the resulting string
30     /// will always return the original code units.
31     #[stable(feature = "rust1", since = "1.0.0")]
32     fn from_wide(wide: &[u16]) -> Self;
33 }
34
35 #[stable(feature = "rust1", since = "1.0.0")]
36 impl OsStringExt for OsString {
37     fn from_wide(wide: &[u16]) -> OsString {
38         FromInner::from_inner(Buf { inner: Wtf8Buf::from_wide(wide) })
39     }
40 }
41
42 /// Windows-specific extensions to `OsStr`.
43 #[stable(feature = "rust1", since = "1.0.0")]
44 pub trait OsStrExt {
45     /// Re-encodes an `OsStr` as a wide character sequence,
46     /// i.e. potentially ill-formed UTF-16.
47     ///
48     /// This is lossless. Note that the encoding does not include a final
49     /// null.
50     #[stable(feature = "rust1", since = "1.0.0")]
51     fn encode_wide(&self) -> EncodeWide;
52 }
53
54 #[stable(feature = "rust1", since = "1.0.0")]
55 impl OsStrExt for OsStr {
56     fn encode_wide(&self) -> EncodeWide {
57         self.as_inner().inner.encode_wide()
58     }
59 }