use std::fmt;
#[derive(Debug)]
pub enum Error {
Io(std::io::Error),
Protocol(String),
Server(String),
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Io(error) => write!(formatter, "{error}"),
Error::Protocol(message) | Error::Server(message) => write!(formatter, "{message}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(error) => Some(error),
Error::Protocol(_) | Error::Server(_) => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Error::Io(error)
}
}