]> git.proxmox.com Git - rustc.git/blob - 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
1 use crate::ffi::OsStr;
2 use crate::fmt;
3 use crate::io;
4 use crate::marker::PhantomData;
5 use crate::path::Path;
6 use crate::sys::fs::File;
7 use crate::sys::pipe::AnonPipe;
8 use crate::sys::{unsupported, Void};
9 use crate::sys_common::process::{CommandEnv, CommandEnvs};
10
11 pub use crate::ffi::OsString as EnvKey;
12
13 ////////////////////////////////////////////////////////////////////////////////
14 // Command
15 ////////////////////////////////////////////////////////////////////////////////
16
17 pub struct Command {
18 env: CommandEnv,
19 }
20
21 // passed back to std::process with the pipes connected to the child, if any
22 // were requested
23 pub struct StdioPipes {
24 pub stdin: Option<AnonPipe>,
25 pub stdout: Option<AnonPipe>,
26 pub stderr: Option<AnonPipe>,
27 }
28
29 pub enum Stdio {
30 Inherit,
31 Null,
32 MakePipe,
33 }
34
35 impl Command {
36 pub fn new(_program: &OsStr) -> Command {
37 Command { env: Default::default() }
38 }
39
40 pub fn arg(&mut self, _arg: &OsStr) {}
41
42 pub fn env_mut(&mut self) -> &mut CommandEnv {
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
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
70 pub fn spawn(
71 &mut self,
72 _default: Stdio,
73 _needs_stdin: bool,
74 ) -> io::Result<(Process, StdioPipes)> {
75 unsupported()
76 }
77 }
78
79 impl From<AnonPipe> for Stdio {
80 fn from(pipe: AnonPipe) -> Stdio {
81 pipe.diverge()
82 }
83 }
84
85 impl From<File> for Stdio {
86 fn from(_file: File) -> Stdio {
87 panic!("unsupported")
88 }
89 }
90
91 impl fmt::Debug for Command {
92 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 Ok(())
94 }
95 }
96
97 pub struct ExitStatus(Void);
98
99 impl 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
109 impl Clone for ExitStatus {
110 fn clone(&self) -> ExitStatus {
111 match self.0 {}
112 }
113 }
114
115 impl Copy for ExitStatus {}
116
117 impl PartialEq for ExitStatus {
118 fn eq(&self, _other: &ExitStatus) -> bool {
119 match self.0 {}
120 }
121 }
122
123 impl Eq for ExitStatus {}
124
125 impl fmt::Debug for ExitStatus {
126 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
127 match self.0 {}
128 }
129 }
130
131 impl fmt::Display for ExitStatus {
132 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
133 match self.0 {}
134 }
135 }
136
137 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
138 pub struct ExitCode(bool);
139
140 impl 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
149 pub struct Process(Void);
150
151 impl 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 }
168
169 pub struct CommandArgs<'a> {
170 _p: PhantomData<&'a ()>,
171 }
172
173 impl<'a> Iterator for CommandArgs<'a> {
174 type Item = &'a OsStr;
175 fn next(&mut self) -> Option<&'a OsStr> {
176 None
177 }
178 }
179
180 impl<'a> ExactSizeIterator for CommandArgs<'a> {}
181
182 impl<'a> fmt::Debug for CommandArgs<'a> {
183 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
184 f.debug_list().finish()
185 }
186 }