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 //! Windows-specific extensions to the primitives in the `std::ffi` module.
13 #![stable(feature = "rust1", since = "1.0.0")]
15 use ffi::{OsString, OsStr};
17 use sys_common::wtf8::Wtf8Buf;
18 use sys_common::{FromInner, AsInner};
20 #[stable(feature = "rust1", since = "1.0.0")]
21 pub use sys_common::wtf8::EncodeWide;
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.
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;
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) })
42 /// Windows-specific extensions to `OsStr`.
43 #[stable(feature = "rust1", since = "1.0.0")]
45 /// Re-encodes an `OsStr` as a wide character sequence,
46 /// i.e. potentially ill-formed UTF-16.
48 /// This is lossless. Note that the encoding does not include a final
50 #[stable(feature = "rust1", since = "1.0.0")]
51 fn encode_wide(&self) -> EncodeWide;
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()