subprocess/os_common.rs
1/// Exit status of a process.
2
3#[derive(Debug, Eq, PartialEq, Copy, Clone)]
4pub enum ExitStatus {
5 /// The process exited with the specified exit code.
6 ///
7 /// Note that the exit code is limited to a much smaller range on most platforms.
8 Exited(u32),
9
10 /// The process exited due to a signal with the specified number.
11 ///
12 /// This variant is never created on Windows, where signals of Unix kind do not exist.
13 Signaled(u8),
14
15 /// The process exit status cannot be described by the preceding two variants.
16 ///
17 /// This should not occur in normal operation.
18 Other(i32),
19
20 /// It is known that the process has completed, but its exit status is unavailable.
21 ///
22 /// This should not occur in normal operation, but is possible if for example some foreign
23 /// code calls `waitpid()` on the PID of the child process.
24 Undetermined,
25}
26
27impl ExitStatus {
28 /// True if the exit status of the process is 0.
29 pub fn success(self) -> bool {
30 matches!(self, ExitStatus::Exited(0))
31 }
32
33 /// True if the subprocess was killed by a signal with the specified number.
34 ///
35 /// You can pass the concrete `libc` signal numbers to this function, such as
36 /// `status.is_killed_by(libc::SIGABRT)`.
37 pub fn is_killed_by<T: Eq + From<u8>>(self, signum: T) -> bool {
38 if let ExitStatus::Signaled(n) = self {
39 let n: T = n.into();
40 return n == signum;
41 }
42 false
43 }
44}
45
46#[derive(Debug, Copy, Clone)]
47#[allow(dead_code)]
48pub enum StandardStream {
49 Input = 0,
50 Output = 1,
51 Error = 2,
52}