summaryrefslogtreecommitdiffstats
path: root/src/util/ipc.rs
blob: 9fa6b9d66c93a7c97f4994a0a6ac327a5148b26b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std::{
	io::{self, Error, ErrorKind},
	result,
};

use ipc_channel::ipc;
pub trait CheckDisconnect {
	type Output;

	fn check_disconnect(self) -> io::Result<Self::Output>;
}

impl<T> CheckDisconnect for result::Result<T, ipc::IpcError> {
	type Output = result::Result<(), T>;

	fn check_disconnect(self) -> io::Result<Self::Output> {
		match self {
			Ok(v) => Ok(Err(v)),
			Err(ipc::IpcError::Disconnected) => Ok(Ok(())),
			Err(error) => Err(Error::new(ErrorKind::Other, error)),
		}
	}
}