Removes unnecessary duplication with a blanket implementation (#571)

This commit is contained in:
Seung-Li Maeda
2020-12-01 22:32:48 -08:00
committed by GitHub
parent f9116dd0f3
commit c62a1149c8
2 changed files with 8 additions and 19 deletions

View File

@@ -12,16 +12,6 @@ pub trait Check {
fn check(self) -> Result<()>;
}
impl Check for ExitStatus {
fn check(self) -> Result<()> {
if self.success() {
Ok(())
} else {
Err(TopgradeError::ProcessFailed(self).into())
}
}
}
impl Check for Output {
fn check(self) -> Result<()> {
self.status.check()
@@ -32,6 +22,14 @@ pub trait CheckWithCodes {
fn check_with_codes(self, codes: &[i32]) -> Result<()>;
}
// Anything that implements CheckWithCodes also implements check
// if check_with_codes is given an empty array of codes to check
impl<T: CheckWithCodes> Check for T {
fn check(self) -> Result<()> {
self.check_with_codes(&[])
}
}
impl CheckWithCodes for ExitStatus {
fn check_with_codes(self, codes: &[i32]) -> Result<()> {
// Set the default to be -1 because the option represents a signal termination