use std::{fmt, io};
#[derive(Debug)]
pub enum Error {
IO(String),
Rocket(String),
Svc(String)
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::IO(s) => write!(f, "I/O error; {s}"),
Self::Rocket(s) => write!(f, "Rocket error; {s}"),
Self::Svc(s) => write!(f, "Service error; {s}")
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IO(err.to_string())
}
}
impl From<qsu::Error> for Error {
fn from(err: qsu::Error) -> Self {
Self::Svc(err.to_string())
}
}
impl From<rocket::Error> for Error {
fn from(err: rocket::Error) -> Self {
Self::Rocket(err.to_string())
}
}
impl From<qsu::CbErr<Self>> for Error {
fn from(err: qsu::CbErr<Self>) -> Self {
match err {
qsu::CbErr::App(ae) => ae,
qsu::CbErr::Lib(le) => Self::Svc(le.to_string()),
qsu::CbErr::SrvApp(sa) => {
if let Some(e) = sa.init {
e
} else if let Some(e) = sa.run {
e
} else if let Some(e) = sa.shutdown {
e
} else {
unimplemented!()
}
}
}
}
}