From ddb92b57fb92a43dcd3ac03ba987636bbc5d1843 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 26 Oct 2021 23:57:33 +0200 Subject: runner: move Checkable trait into separabe module --- crates/runner/src/util/checkable.rs | 37 +++++++++++++++++++++++++++++++++++ crates/runner/src/util/mod.rs | 39 +------------------------------------ 2 files changed, 38 insertions(+), 38 deletions(-) create mode 100644 crates/runner/src/util/checkable.rs (limited to 'crates/runner/src/util') diff --git a/crates/runner/src/util/checkable.rs b/crates/runner/src/util/checkable.rs new file mode 100644 index 0000000..8528d29 --- /dev/null +++ b/crates/runner/src/util/checkable.rs @@ -0,0 +1,37 @@ +use std::{ + io::{Error, ErrorKind, Result}, + process::ExitStatus, +}; + +use nix::sys::wait; + +pub trait Checkable { + fn check(&self) -> Result<()>; +} + +impl Checkable for ExitStatus { + fn check(&self) -> Result<()> { + if self.success() { + Ok(()) + } else { + Err(Error::new( + ErrorKind::Other, + format!("Process exited with {}", self), + )) + } + } +} + +impl Checkable for wait::WaitStatus { + fn check(&self) -> Result<()> { + let message = match self { + wait::WaitStatus::Exited(_, 0) => return Ok(()), + wait::WaitStatus::Exited(_, code) => format!("Process exited with exit code: {}", code), + wait::WaitStatus::Signaled(_, signal, _) => { + format!("Process exited with signal: {}", signal) + } + _ => format!("Process in unexpected status: {:?}", self), + }; + Err(Error::new(ErrorKind::Other, message)) + } +} diff --git a/crates/runner/src/util/mod.rs b/crates/runner/src/util/mod.rs index eff589d..5310ccf 100644 --- a/crates/runner/src/util/mod.rs +++ b/crates/runner/src/util/mod.rs @@ -1,42 +1,5 @@ +pub mod checkable; pub mod cjson; pub mod clone; pub mod fs; pub mod unix; - -use std::{ - io::{Error, ErrorKind, Result}, - process::ExitStatus, -}; - -use nix::sys::wait; - -pub trait Checkable { - fn check(&self) -> Result<()>; -} - -impl Checkable for ExitStatus { - fn check(&self) -> Result<()> { - if self.success() { - Ok(()) - } else { - Err(Error::new( - ErrorKind::Other, - format!("Process exited with {}", self), - )) - } - } -} - -impl Checkable for wait::WaitStatus { - fn check(&self) -> Result<()> { - let message = match self { - wait::WaitStatus::Exited(_, 0) => return Ok(()), - wait::WaitStatus::Exited(_, code) => format!("Process exited with exit code: {}", code), - wait::WaitStatus::Signaled(_, signal, _) => { - format!("Process exited with signal: {}", signal) - } - _ => format!("Process in unexpected status: {:?}", self), - }; - Err(Error::new(ErrorKind::Other, message)) - } -} -- cgit v1.2.3