use self::Kind::*;
use std::error;
use std::fmt;
#[derive(Debug)]
pub struct Error(Kind);
#[derive(Debug)]
enum Kind {
Shutdown,
AtCapacity,
}
impl Error {
pub fn shutdown() -> Error {
Error(Shutdown)
}
pub fn is_shutdown(&self) -> bool {
match self.0 {
Kind::Shutdown => true,
_ => false,
}
}
pub fn at_capacity() -> Error {
Error(AtCapacity)
}
pub fn is_at_capacity(&self) -> bool {
match self.0 {
Kind::AtCapacity => true,
_ => false,
}
}
}
impl error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::Kind::*;
let descr = match self.0 {
Shutdown => "timer is shutdown",
AtCapacity => "timer is at capacity and cannot create a new entry",
};
write!(fmt, "{}", descr)
}
}