use std::{process::Output, string::FromUtf8Error};
pub trait OutputExt {
fn stdout(&self) -> Result<String, FromUtf8Error>;
fn stderr(&self) -> Result<String, FromUtf8Error>;
fn stdout_lossy(&self) -> String;
fn stderr_lossy(&self) -> String;
}
impl OutputExt for Output {
fn stdout(&self) -> Result<String, FromUtf8Error> {
String::from_utf8(self.stdout.clone()).map(|x| x.trim_end_matches('\n').to_owned())
}
fn stderr(&self) -> Result<String, FromUtf8Error> {
String::from_utf8(self.stderr.clone()).map(|x| x.trim_end_matches('\n').to_owned())
}
fn stdout_lossy(&self) -> String {
String::from_utf8_lossy(&self.stdout)
.trim_end_matches('\n')
.to_owned()
}
fn stderr_lossy(&self) -> String {
String::from_utf8_lossy(&self.stderr)
.trim_end_matches('\n')
.to_owned()
}
}