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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
use std::error; use std::fmt; use telegram_bot_raw; #[derive(Debug)] pub struct Error(ErrorKind); #[derive(Debug)] pub(crate) enum ErrorKind { Raw(telegram_bot_raw::Error), Hyper(hyper::Error), Http(hyper::http::Error), Io(std::io::Error), InvalidMultipartFilename, } impl From<telegram_bot_raw::Error> for ErrorKind { fn from(error: telegram_bot_raw::Error) -> Self { ErrorKind::Raw(error) } } impl From<hyper::Error> for ErrorKind { fn from(error: hyper::Error) -> Self { ErrorKind::Hyper(error) } } impl From<hyper::http::Error> for ErrorKind { fn from(error: hyper::http::Error) -> Self { ErrorKind::Http(error) } } impl From<std::io::Error> for ErrorKind { fn from(error: std::io::Error) -> Self { ErrorKind::Io(error) } } impl From<ErrorKind> for Error { fn from(kind: ErrorKind) -> Self { Error(kind) } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.0 { ErrorKind::Raw(error) => write!(f, "{}", error), ErrorKind::Hyper(error) => write!(f, "{}", error), ErrorKind::Http(error) => write!(f, "{}", error), ErrorKind::Io(error) => write!(f, "{}", error), ErrorKind::InvalidMultipartFilename => write!(f, "invalid multipart filename"), } } } impl error::Error for Error {}