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