use std::fmt;
#[derive(Debug, PartialEq, Eq)]
pub enum Error<S, E> {
Aborted(S),
LostWaiter,
App(E)
}
impl<S, E> Error<S, E> {
pub fn into_apperr(self) -> Option<E> {
match self {
Self::App(e) => Some(e),
_ => None
}
}
pub fn unwrap_apperr(self) -> E {
match self {
Self::App(e) => e,
_ => panic!("Not an Error::App")
}
}
}
impl<S: fmt::Debug, E> std::error::Error for Error<S, E> where
E: std::error::Error
{
}
impl<S, E> fmt::Display for Error<S, E>
where
E: std::error::Error
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Aborted(_) => {
write!(f, "The set context was dropped prematurely")
}
Self::LostWaiter => write!(f, "WaitCtx disappeared"),
Self::App(err) => write!(f, "Application error; {:?}", err)
}
}
}