use std::fmt;
#[derive(Debug)]
pub enum Error<E> {
App(E),
QueueFull,
ReceiverDisappeared,
RecordsUnderflow
}
impl<E> Error<E> {
pub fn into_apperr(self) -> Option<E> {
match self {
Error::App(e) => Some(e),
_ => None
}
}
pub fn unwrap_apperr(self) -> E {
match self {
Error::App(e) => e,
_ => panic!("Not an Error::App")
}
}
}
impl<E: fmt::Debug> std::error::Error for Error<E> {}
impl<E: fmt::Debug> fmt::Display for Error<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::App(err) => write!(f, "Application error; {:?}", err),
Error::QueueFull => write!(f, "Queue full"),
Error::ReceiverDisappeared => {
write!(f, "The receiver disappeared")
}
Error::RecordsUnderflow => {
write!(f, "Sender disappeared before sending all expected records")
}
}
}
}