]> git.proxmox.com Git - rustc.git/blame - library/std/src/sys/unsupported/process.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / library / std / src / sys / unsupported / process.rs
CommitLineData
532ac7d7
XL
1use crate::ffi::OsStr;
2use crate::fmt;
3use crate::io;
1b1a35ee
XL
4use crate::marker::PhantomData;
5use crate::path::Path;
532ac7d7
XL
6use crate::sys::fs::File;
7use crate::sys::pipe::AnonPipe;
8use crate::sys::{unsupported, Void};
1b1a35ee 9use crate::sys_common::process::{CommandEnv, CommandEnvs};
e1599b0c
XL
10
11pub use crate::ffi::OsString as EnvKey;
2c00a5a8
XL
12
13////////////////////////////////////////////////////////////////////////////////
14// Command
15////////////////////////////////////////////////////////////////////////////////
16
17pub struct Command {
e1599b0c 18 env: CommandEnv,
2c00a5a8
XL
19}
20
21// passed back to std::process with the pipes connected to the child, if any
22// were requested
23pub struct StdioPipes {
24 pub stdin: Option<AnonPipe>,
25 pub stdout: Option<AnonPipe>,
26 pub stderr: Option<AnonPipe>,
27}
28
29pub enum Stdio {
30 Inherit,
31 Null,
32 MakePipe,
33}
34
35impl Command {
36 pub fn new(_program: &OsStr) -> Command {
60c5eb7d 37 Command { env: Default::default() }
2c00a5a8
XL
38 }
39
40 pub fn arg(&mut self, _arg: &OsStr) {}
41
e1599b0c 42 pub fn env_mut(&mut self) -> &mut CommandEnv {
2c00a5a8
XL
43 &mut self.env
44 }
45
46 pub fn cwd(&mut self, _dir: &OsStr) {}
47
48 pub fn stdin(&mut self, _stdin: Stdio) {}
49
50 pub fn stdout(&mut self, _stdout: Stdio) {}
51
52 pub fn stderr(&mut self, _stderr: Stdio) {}
53
1b1a35ee
XL
54 pub fn get_program(&self) -> &OsStr {
55 panic!("unsupported")
56 }
57
58 pub fn get_args(&self) -> CommandArgs<'_> {
59 CommandArgs { _p: PhantomData }
60 }
61
62 pub fn get_envs(&self) -> CommandEnvs<'_> {
63 self.env.iter()
64 }
65
66 pub fn get_current_dir(&self) -> Option<&Path> {
67 None
68 }
69
2c00a5a8
XL
70 pub fn spawn(
71 &mut self,
72 _default: Stdio,
73 _needs_stdin: bool,
74 ) -> io::Result<(Process, StdioPipes)> {
75 unsupported()
76 }
77}
78
79impl From<AnonPipe> for Stdio {
80 fn from(pipe: AnonPipe) -> Stdio {
81 pipe.diverge()
82 }
83}
84
85impl From<File> for Stdio {
1b1a35ee
XL
86 fn from(_file: File) -> Stdio {
87 panic!("unsupported")
2c00a5a8
XL
88 }
89}
90
91impl fmt::Debug for Command {
532ac7d7 92 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
2c00a5a8
XL
93 Ok(())
94 }
95}
96
97pub struct ExitStatus(Void);
98
99impl ExitStatus {
100 pub fn success(&self) -> bool {
101 match self.0 {}
102 }
103
104 pub fn code(&self) -> Option<i32> {
105 match self.0 {}
106 }
107}
108
109impl Clone for ExitStatus {
110 fn clone(&self) -> ExitStatus {
111 match self.0 {}
112 }
113}
114
115impl Copy for ExitStatus {}
116
117impl PartialEq for ExitStatus {
118 fn eq(&self, _other: &ExitStatus) -> bool {
119 match self.0 {}
120 }
121}
122
123impl Eq for ExitStatus {}
124
125impl fmt::Debug for ExitStatus {
532ac7d7 126 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
2c00a5a8
XL
127 match self.0 {}
128 }
129}
130
131impl fmt::Display for ExitStatus {
532ac7d7 132 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
2c00a5a8
XL
133 match self.0 {}
134 }
135}
136
0531ce1d
XL
137#[derive(PartialEq, Eq, Clone, Copy, Debug)]
138pub struct ExitCode(bool);
139
140impl ExitCode {
141 pub const SUCCESS: ExitCode = ExitCode(false);
142 pub const FAILURE: ExitCode = ExitCode(true);
143
144 pub fn as_i32(&self) -> i32 {
145 self.0 as i32
146 }
147}
148
2c00a5a8
XL
149pub struct Process(Void);
150
151impl Process {
152 pub fn id(&self) -> u32 {
153 match self.0 {}
154 }
155
156 pub fn kill(&mut self) -> io::Result<()> {
157 match self.0 {}
158 }
159
160 pub fn wait(&mut self) -> io::Result<ExitStatus> {
161 match self.0 {}
162 }
163
164 pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
165 match self.0 {}
166 }
167}
1b1a35ee
XL
168
169pub struct CommandArgs<'a> {
170 _p: PhantomData<&'a ()>,
171}
172
173impl<'a> Iterator for CommandArgs<'a> {
174 type Item = &'a OsStr;
175 fn next(&mut self) -> Option<&'a OsStr> {
176 None
177 }
178}
179
180impl<'a> ExactSizeIterator for CommandArgs<'a> {}
181
182impl<'a> fmt::Debug for CommandArgs<'a> {
183 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
184 f.debug_list().finish()
185 }
186}