From 5c7677e5fa134b60c7d4c29d3643125901a31fb8 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 13 Sep 2020 17:58:51 +0200 Subject: WIP rust client --- rust/src/error.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rust/src/error.rs (limited to 'rust/src/error.rs') diff --git a/rust/src/error.rs b/rust/src/error.rs new file mode 100644 index 0000000..f25bc5d --- /dev/null +++ b/rust/src/error.rs @@ -0,0 +1,27 @@ +use std::io; + +pub trait IntoIOError { + fn ioerr(self) -> io::Error; + fn perror(self, parent: io::Error) -> io::Error; +} + +// This impl bound is taken directly from the io::Error::new function. +impl>> IntoIOError for E { + fn ioerr(self) -> io::Error { + io::Error::new(io::ErrorKind::Other, self) + } + + fn perror(self, parent: io::Error) -> io::Error { + io::Error::new(parent.kind(), format!("{}: {}", self.into(), parent)) + } +} + +pub trait IntoIOResult { + fn iores(self) -> io::Result; +} + +impl IntoIOResult for Result { + fn iores(self) -> io::Result { + self.map_err(|e| e.ioerr()) + } +} -- cgit v1.2.3-70-g09d2