command_error/
output_like.rsuse std::borrow::Cow;
use std::process::ExitStatus;
use std::process::Output;
use utf8_command::Utf8Output;
pub trait OutputLike {
fn status(&self) -> ExitStatus;
fn stdout(&self) -> Cow<'_, str>;
fn stderr(&self) -> Cow<'_, str>;
}
impl OutputLike for ExitStatus {
fn status(&self) -> ExitStatus {
*self
}
fn stdout(&self) -> Cow<'_, str> {
Cow::Borrowed("")
}
fn stderr(&self) -> Cow<'_, str> {
Cow::Borrowed("")
}
}
impl OutputLike for Output {
fn status(&self) -> ExitStatus {
self.status
}
fn stdout(&self) -> Cow<'_, str> {
String::from_utf8_lossy(&self.stdout)
}
fn stderr(&self) -> Cow<'_, str> {
String::from_utf8_lossy(&self.stderr)
}
}
impl OutputLike for Utf8Output {
fn status(&self) -> ExitStatus {
self.status
}
fn stdout(&self) -> Cow<'_, str> {
Cow::Borrowed(&self.stdout)
}
fn stderr(&self) -> Cow<'_, str> {
Cow::Borrowed(&self.stderr)
}
}