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
#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
use std::os::unix::prelude::ExitStatusExt;
use std::process::Output;

pub trait OutputExt {
	fn success(&self) -> bool;
	fn error(&self) -> bool;
	fn has_stdout(&self) -> bool;

	#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
	fn has_signal(&self) -> bool;

	#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
	fn signal(&self) -> Option<i32>;

	fn interrupt(&self) -> bool;
	fn kill(&self) -> bool;
}

impl OutputExt for Output {
	fn success(&self) -> bool {
		self.status.success()
	}
	fn error(&self) -> bool {
		!self.status.success()
	}

	fn has_stdout(&self) -> bool {
		!self.stdout.is_empty()
	}

	#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
	fn has_signal(&self) -> bool {
		self.status.signal().is_some()
	}

	#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
	fn signal(&self) -> Option<i32> {
		self.status.signal()
	}

	fn interrupt(&self) -> bool {
		self.signal().map(|s| signal_hook::consts::SIGINT == s).unwrap_or(false)
	}

	fn kill(&self) -> bool {
		self.signal().map(|s| signal_hook::consts::SIGKILL == s).unwrap_or(false)
	}
}