1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::fmt;
use {Signal};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExitStatus {
Exited(i8),
Signaled(Signal, bool)
}
impl ExitStatus {
pub fn success(&self) -> bool {
self == &ExitStatus::Exited(0)
}
pub fn code(&self) -> Option<i32> {
match self {
&ExitStatus::Exited(e) => Some(e as i32),
&ExitStatus::Signaled(_, _) => None,
}
}
pub fn signal(&self) -> Option<i32> {
match self {
&ExitStatus::Exited(_) => None,
&ExitStatus::Signaled(sig, _) => Some(sig as i32),
}
}
}
impl fmt::Display for ExitStatus {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use self::ExitStatus::*;
match self {
&Exited(c) => write!(fmt, "exited with code {}", c),
&Signaled(sig, false) => {
write!(fmt, "killed by signal {:?}[{}]",
sig, sig as i32)
}
&Signaled(sig, true) => {
write!(fmt, "killed by signal {:?}[{}] (core dumped)",
sig, sig as i32)
}
}
}
}