command_error/
output_like.rs1use std::borrow::Cow;
2use std::process::ExitStatus;
3use std::process::Output;
4
5use utf8_command::Utf8Output;
6
7pub trait OutputLike {
9 fn status(&self) -> ExitStatus;
11
12 fn stdout(&self) -> Cow<'_, str>;
14
15 fn stderr(&self) -> Cow<'_, str>;
17}
18
19impl OutputLike for ExitStatus {
21 fn status(&self) -> ExitStatus {
22 *self
23 }
24
25 fn stdout(&self) -> Cow<'_, str> {
26 Cow::Borrowed("")
27 }
28
29 fn stderr(&self) -> Cow<'_, str> {
30 Cow::Borrowed("")
31 }
32}
33
34impl OutputLike for Output {
35 fn status(&self) -> ExitStatus {
36 self.status
37 }
38
39 fn stdout(&self) -> Cow<'_, str> {
40 String::from_utf8_lossy(&self.stdout)
41 }
42
43 fn stderr(&self) -> Cow<'_, str> {
44 String::from_utf8_lossy(&self.stderr)
45 }
46}
47
48impl OutputLike for Utf8Output {
49 fn status(&self) -> ExitStatus {
50 self.status
51 }
52
53 fn stdout(&self) -> Cow<'_, str> {
54 Cow::Borrowed(&self.stdout)
55 }
56
57 fn stderr(&self) -> Cow<'_, str> {
58 Cow::Borrowed(&self.stderr)
59 }
60}