summaryrefslogtreecommitdiffstats
path: root/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs
index 4e996e8..0418c51 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,8 +1,10 @@
use std::{
io::{Error, ErrorKind, Result},
process::ExitStatus,
+ result,
};
+use ipc_channel::ipc;
use nix::sys::wait;
pub trait ToIOResult<T> {
@@ -46,3 +48,21 @@ impl Checkable for wait::WaitStatus {
}
}
}
+
+pub trait CheckDisconnect {
+ type Output;
+
+ fn check_disconnect(self) -> Result<Self::Output>;
+}
+
+impl<T> CheckDisconnect for result::Result<T, ipc::IpcError> {
+ type Output = result::Result<(), T>;
+
+ fn check_disconnect(self) -> Result<Self::Output> {
+ match self {
+ Ok(v) => Ok(Err(v)),
+ Err(ipc::IpcError::Disconnected) => Ok(Ok(())),
+ Err(error) => Err(Error::new(ErrorKind::Other, format!("{:?}", error))),
+ }
+ }
+}