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()) } }