]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/ext/process.rs
change the format of the linked issue number
[rust.git] / src / libstd / sys / windows / ext / process.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 //! Extensions to `std::process` for Windows.
12
13 #![stable(feature = "process_extensions", since = "1.2.0")]
14
15 use os::windows::io::{FromRawHandle, RawHandle, AsRawHandle, IntoRawHandle};
16 use process;
17 use sys;
18 use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner};
19
20 #[stable(feature = "process_extensions", since = "1.2.0")]
21 impl FromRawHandle for process::Stdio {
22     unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio {
23         let handle = sys::handle::Handle::new(handle as *mut _);
24         let io = sys::process::Stdio::Handle(handle);
25         process::Stdio::from_inner(io)
26     }
27 }
28
29 #[stable(feature = "process_extensions", since = "1.2.0")]
30 impl AsRawHandle for process::Child {
31     fn as_raw_handle(&self) -> RawHandle {
32         self.as_inner().handle().raw() as *mut _
33     }
34 }
35
36 #[stable(feature = "into_raw_os", since = "1.4.0")]
37 impl IntoRawHandle for process::Child {
38     fn into_raw_handle(self) -> RawHandle {
39         self.into_inner().into_handle().into_raw() as *mut _
40     }
41 }
42
43 #[stable(feature = "process_extensions", since = "1.2.0")]
44 impl AsRawHandle for process::ChildStdin {
45     fn as_raw_handle(&self) -> RawHandle {
46         self.as_inner().handle().raw() as *mut _
47     }
48 }
49
50 #[stable(feature = "process_extensions", since = "1.2.0")]
51 impl AsRawHandle for process::ChildStdout {
52     fn as_raw_handle(&self) -> RawHandle {
53         self.as_inner().handle().raw() as *mut _
54     }
55 }
56
57 #[stable(feature = "process_extensions", since = "1.2.0")]
58 impl AsRawHandle for process::ChildStderr {
59     fn as_raw_handle(&self) -> RawHandle {
60         self.as_inner().handle().raw() as *mut _
61     }
62 }
63
64 #[stable(feature = "into_raw_os", since = "1.4.0")]
65 impl IntoRawHandle for process::ChildStdin {
66     fn into_raw_handle(self) -> RawHandle {
67         self.into_inner().into_handle().into_raw() as *mut _
68     }
69 }
70
71 #[stable(feature = "into_raw_os", since = "1.4.0")]
72 impl IntoRawHandle for process::ChildStdout {
73     fn into_raw_handle(self) -> RawHandle {
74         self.into_inner().into_handle().into_raw() as *mut _
75     }
76 }
77
78 #[stable(feature = "into_raw_os", since = "1.4.0")]
79 impl IntoRawHandle for process::ChildStderr {
80     fn into_raw_handle(self) -> RawHandle {
81         self.into_inner().into_handle().into_raw() as *mut _
82     }
83 }
84
85 /// Windows-specific extensions to `std::process::ExitStatus`
86 #[stable(feature = "exit_status_from", since = "1.12.0")]
87 pub trait ExitStatusExt {
88     /// Creates a new `ExitStatus` from the raw underlying `u32` return value of
89     /// a process.
90     #[stable(feature = "exit_status_from", since = "1.12.0")]
91     fn from_raw(raw: u32) -> Self;
92 }
93
94 #[stable(feature = "exit_status_from", since = "1.12.0")]
95 impl ExitStatusExt for process::ExitStatus {
96     fn from_raw(raw: u32) -> Self {
97         process::ExitStatus::from_inner(From::from(raw))
98     }
99 }
100
101 /// Windows-specific extensions to the `std::process::Command` builder
102 #[stable(feature = "windows_process_extensions", since = "1.16.0")]
103 pub trait CommandExt {
104     /// Sets the [process creation flags][1] to be passed to `CreateProcess`.
105     ///
106     /// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`.
107     /// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx
108     #[stable(feature = "windows_process_extensions", since = "1.16.0")]
109     fn creation_flags(&mut self, flags: u32) -> &mut process::Command;
110 }
111
112 #[stable(feature = "windows_process_extensions", since = "1.16.0")]
113 impl CommandExt for process::Command {
114     fn creation_flags(&mut self, flags: u32) -> &mut process::Command {
115         self.as_inner_mut().creation_flags(flags);
116         self
117     }
118 }