1use std::error;
5use std::fmt;
6
7pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum Error {
13 Generic(String),
15 UrlParse(String),
17 MsgPack(String),
19 ProgrammingError(&'static str),
21 MissingContent(&'static str),
23 Padding(&'static str),
25 Base64(&'static str),
27 Encryption(&'static str),
29 Unauthorized(String),
31 Conflict(String),
33 PermissionDenied(String),
35 NotFound(String),
37
38 Connection(String),
40 TemporaryServerError(String),
42 ServerError(String),
44 Http(String),
46}
47
48impl fmt::Display for Error {
49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50 match self {
51 Error::Generic(s) => s.fmt(f),
52 Error::UrlParse(s) => s.fmt(f),
53 Error::MsgPack(s) => s.fmt(f),
54 Error::ProgrammingError(s) => s.fmt(f),
55 Error::MissingContent(s) => s.fmt(f),
56 Error::Padding(s) => s.fmt(f),
57 Error::Base64(s) => s.fmt(f),
58 Error::Encryption(s) => s.fmt(f),
59 Error::PermissionDenied(s) => s.fmt(f),
60 Error::NotFound(s) => s.fmt(f),
61 Error::Unauthorized(s) => s.fmt(f),
62 Error::Conflict(s) => s.fmt(f),
63
64 Error::Connection(s) => s.fmt(f),
65 Error::TemporaryServerError(s) => s.fmt(f),
66 Error::ServerError(s) => s.fmt(f),
67 Error::Http(s) => s.fmt(f),
68 }
69 }
70}
71
72impl From<Error> for String {
73 fn from(err: Error) -> String {
74 err.to_string()
75 }
76}
77
78impl error::Error for Error {
79 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
80 None
81 }
82}
83
84impl From<String> for Error {
85 fn from(err: String) -> Error {
86 Error::Generic(err)
87 }
88}
89
90impl From<url::ParseError> for Error {
91 fn from(err: url::ParseError) -> Error {
92 Error::UrlParse(err.to_string())
93 }
94}
95
96impl From<std::ffi::NulError> for Error {
97 fn from(err: std::ffi::NulError) -> Error {
98 Error::Generic(err.to_string())
99 }
100}
101
102impl From<std::io::Error> for Error {
103 fn from(err: std::io::Error) -> Error {
104 Error::UrlParse(err.to_string())
105 }
106}
107
108impl From<rmp_serde::encode::Error> for Error {
109 fn from(err: rmp_serde::encode::Error) -> Error {
110 Error::MsgPack(err.to_string())
111 }
112}
113
114impl From<rmp_serde::decode::Error> for Error {
115 fn from(err: rmp_serde::decode::Error) -> Error {
116 Error::MsgPack(err.to_string())
117 }
118}