#[derive(Debug)]
pub enum StaartError {
IO(std::io::Error),
Utf8(std::str::Utf8Error),
IntError(std::num::TryFromIntError),
}
impl std::fmt::Display for StaartError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
StaartError::IO(..) => {
write!(f, "encountered IO error")
}
StaartError::Utf8(..) => {
write!(f, "encountered UTF8 error")
}
StaartError::IntError(..) => {
write!(f, "encountered integer conversion error")
}
}
}
}
impl std::error::Error for StaartError {}
impl From<std::io::Error> for StaartError {
fn from(err: std::io::Error) -> Self {
StaartError::IO(err)
}
}
impl From<std::str::Utf8Error> for StaartError {
fn from(err: std::str::Utf8Error) -> Self {
StaartError::Utf8(err)
}
}
impl From<std::num::TryFromIntError> for StaartError {
fn from(err: std::num::TryFromIntError) -> Self {
StaartError::IntError(err)
}
}