-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_output.rs
More file actions
75 lines (66 loc) · 1.54 KB
/
Copy pathexecute_output.rs
File metadata and controls
75 lines (66 loc) · 1.54 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::{
io::{Write, stdout},
process::Output,
};
#[derive(Debug, PartialEq)]
pub(crate) struct ExecuteOutput {
pub(crate) out: String,
pub(crate) err: String,
pub(crate) exit: bool,
}
impl ExecuteOutput {
pub(crate) const fn new() -> Self {
Self {
out: String::new(),
err: String::new(),
exit: false,
}
}
pub(crate) fn err(value: String) -> Self {
Self {
err: value,
..ExecuteOutput::new()
}
}
pub(crate) fn exit() -> Self {
Self {
exit: true,
..ExecuteOutput::new()
}
}
}
impl From<String> for ExecuteOutput {
fn from(value: String) -> Self {
Self {
out: value,
..Self::new()
}
}
}
impl From<&str> for ExecuteOutput {
fn from(value: &str) -> Self {
format!("{value}").into()
}
}
impl From<Option<String>> for ExecuteOutput {
fn from(value: Option<String>) -> Self {
match value {
Some(value) => Self {
out: value,
..Self::new()
},
None => Self::new(),
}
}
}
impl From<Output> for ExecuteOutput {
fn from(value: Output) -> Self {
// stdout().write(&value.stderr).unwrap();
// stdout().flush().unwrap();
Self {
out: String::from_utf8_lossy(&value.stdout).into_owned(),
err: String::from_utf8_lossy(&value.stderr).into_owned(),
..ExecuteOutput::new()
}
}
}