From 30e1e3a13dc19c47afc517d1178e1dbf5b401596 Mon Sep 17 00:00:00 2001 From: syn Date: Sun, 9 Feb 2020 19:17:57 +0300 Subject: timeout'ed waiter for process --- src/wait/error.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/wait/error.rs (limited to 'src/wait/error.rs') diff --git a/src/wait/error.rs b/src/wait/error.rs new file mode 100644 index 0000000..bb95e81 --- /dev/null +++ b/src/wait/error.rs @@ -0,0 +1,32 @@ +use nix; +use std::time::Duration; + +#[derive(Debug)] +pub enum WaitError { + TimedOut(Duration), + OsError(nix::Error) +} + +impl From for WaitError { + fn from(err: nix::Error) -> Self { + WaitError::OsError(err) + } +} + +impl std::fmt::Display for WaitError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match *self { + WaitError::TimedOut(dur) => write!(f, "process timed out in {:?}", dur), + WaitError::OsError(err) => err.fmt(f) + } + } +} + +impl std::error::Error for WaitError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match *self { + WaitError::TimedOut(_) => None, + WaitError::OsError(ref e) => Some(e) + } + } +} \ No newline at end of file -- cgit v1.2.1-18-gbd029