]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/hermit/process.rs
4702e5c549228ea27e5c59777cb707b34ea5d248
[rust.git] / library / std / src / sys / hermit / process.rs
1 use crate::ffi::OsStr;
2 use crate::fmt;
3 use crate::io;
4 use crate::sys::fs::File;
5 use crate::sys::pipe::AnonPipe;
6 use crate::sys::{unsupported, Void};
7 use crate::sys_common::process::CommandEnv;
8
9 pub use crate::ffi::OsString as EnvKey;
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // Command
13 ////////////////////////////////////////////////////////////////////////////////
14
15 pub struct Command {
16     env: CommandEnv,
17 }
18
19 // passed back to std::process with the pipes connected to the child, if any
20 // were requested
21 pub struct StdioPipes {
22     pub stdin: Option<AnonPipe>,
23     pub stdout: Option<AnonPipe>,
24     pub stderr: Option<AnonPipe>,
25 }
26
27 pub enum Stdio {
28     Inherit,
29     Null,
30     MakePipe,
31 }
32
33 impl Command {
34     pub fn new(_program: &OsStr) -> Command {
35         Command { env: Default::default() }
36     }
37
38     pub fn arg(&mut self, _arg: &OsStr) {}
39
40     pub fn env_mut(&mut self) -> &mut CommandEnv {
41         &mut self.env
42     }
43
44     pub fn cwd(&mut self, _dir: &OsStr) {}
45
46     pub fn stdin(&mut self, _stdin: Stdio) {}
47
48     pub fn stdout(&mut self, _stdout: Stdio) {}
49
50     pub fn stderr(&mut self, _stderr: Stdio) {}
51
52     pub fn spawn(
53         &mut self,
54         _default: Stdio,
55         _needs_stdin: bool,
56     ) -> io::Result<(Process, StdioPipes)> {
57         unsupported()
58     }
59 }
60
61 impl From<AnonPipe> for Stdio {
62     fn from(pipe: AnonPipe) -> Stdio {
63         pipe.diverge()
64     }
65 }
66
67 impl From<File> for Stdio {
68     fn from(file: File) -> Stdio {
69         file.diverge()
70     }
71 }
72
73 impl fmt::Debug for Command {
74     fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
75         Ok(())
76     }
77 }
78
79 pub struct ExitStatus(Void);
80
81 impl ExitStatus {
82     pub fn success(&self) -> bool {
83         match self.0 {}
84     }
85
86     pub fn code(&self) -> Option<i32> {
87         match self.0 {}
88     }
89 }
90
91 impl Clone for ExitStatus {
92     fn clone(&self) -> ExitStatus {
93         match self.0 {}
94     }
95 }
96
97 impl Copy for ExitStatus {}
98
99 impl PartialEq for ExitStatus {
100     fn eq(&self, _other: &ExitStatus) -> bool {
101         match self.0 {}
102     }
103 }
104
105 impl Eq for ExitStatus {}
106
107 impl fmt::Debug for ExitStatus {
108     fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
109         match self.0 {}
110     }
111 }
112
113 impl fmt::Display for ExitStatus {
114     fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
115         match self.0 {}
116     }
117 }
118
119 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
120 pub struct ExitCode(bool);
121
122 impl ExitCode {
123     pub const SUCCESS: ExitCode = ExitCode(false);
124     pub const FAILURE: ExitCode = ExitCode(true);
125
126     pub fn as_i32(&self) -> i32 {
127         self.0 as i32
128     }
129 }
130
131 pub struct Process(Void);
132
133 impl Process {
134     pub fn id(&self) -> u32 {
135         match self.0 {}
136     }
137
138     pub fn kill(&mut self) -> io::Result<()> {
139         match self.0 {}
140     }
141
142     pub fn wait(&mut self) -> io::Result<ExitStatus> {
143         match self.0 {}
144     }
145
146     pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
147         match self.0 {}
148     }
149 }