1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 Io(std::io::Error),
8 Protocol(String),
10 Server(String),
12}
13
14impl fmt::Display for Error {
15 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 Error::Io(error) => write!(formatter, "{error}"),
18 Error::Protocol(message) | Error::Server(message) => write!(formatter, "{message}"),
19 }
20 }
21}
22
23impl std::error::Error for Error {
24 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
25 match self {
26 Error::Io(error) => Some(error),
27 Error::Protocol(_) | Error::Server(_) => None,
28 }
29 }
30}
31
32impl From<std::io::Error> for Error {
33 fn from(error: std::io::Error) -> Self {
34 Error::Io(error)
35 }
36}