1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
use std::convert::Infallible; use err_derive::Error; use crate::rpc::RequestId; #[derive(Debug, Error)] pub enum Error { #[error(display = "no response for request {}", _0)] MissingResponse(RequestId), #[error(display = "unrelated respond for request {}", _0)] ResponseMismatch(RequestId), #[error(display = "io error: {}", _0)] Io(std::io::Error), #[error(display = "other error: {}", _0)] Other(Box<dyn std::error::Error + Sync + Send + 'static>), } impl From<std::io::Error> for Error { fn from(e: std::io::Error) -> Self { Self::Io(e) } } impl From<Infallible> for Error { fn from(_: Infallible) -> Self { unreachable!() } } impl<E: std::error::Error + Sync + Send + 'static> From<Box<E>> for Error { fn from(e: Box<E>) -> Self { Self::Other(e) } }