1#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
2use std::os::unix::prelude::ExitStatusExt;
3use std::process::Output;
4
5pub trait OutputExt {
6 fn success(&self) -> bool;
7 fn error(&self) -> bool;
8 fn has_stdout(&self) -> bool;
9
10 #[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
11 fn has_signal(&self) -> bool;
12
13 #[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
14 fn signal(&self) -> Option<i32>;
15
16 fn interrupt(&self) -> bool;
17 fn kill(&self) -> bool;
18}
19
20impl OutputExt for Output {
21 fn success(&self) -> bool {
22 self.status.success()
23 }
24 fn error(&self) -> bool {
25 !self.status.success()
26 }
27
28 fn has_stdout(&self) -> bool {
29 !self.stdout.is_empty()
30 }
31
32 #[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
33 fn has_signal(&self) -> bool {
34 self.status.signal().is_some()
35 }
36
37 #[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
38 fn signal(&self) -> Option<i32> {
39 self.status.signal()
40 }
41
42 fn interrupt(&self) -> bool {
43 self.signal().map(|s| signal_hook::consts::SIGINT == s).unwrap_or(false)
44 }
45
46 fn kill(&self) -> bool {
47 self.signal().map(|s| signal_hook::consts::SIGKILL == s).unwrap_or(false)
48 }
49}