Removes unnecessary duplication with a blanket implementation (#571)
This commit is contained in:
@@ -230,15 +230,6 @@ pub enum ExecutorExitStatus {
|
||||
Dry,
|
||||
}
|
||||
|
||||
impl Check for ExecutorExitStatus {
|
||||
fn check(self) -> Result<()> {
|
||||
match self {
|
||||
ExecutorExitStatus::Wet(e) => e.check(),
|
||||
ExecutorExitStatus::Dry => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CheckWithCodes for ExecutorExitStatus {
|
||||
fn check_with_codes(self, codes: &[i32]) -> Result<()> {
|
||||
match self {
|
||||
|
||||
18
src/utils.rs
18
src/utils.rs
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user