use std::error::Error;
use std::fmt;
use std::io;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ParseError {
OverflowError,
ParseIntError,
UnsupportedBase,
}
unsafe impl Send for ParseError {}
unsafe impl Sync for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::OverflowError => write!(f, "Overflow"),
ParseError::ParseIntError => write!(f, "Could not parse integer"),
ParseError::UnsupportedBase => write!(f, "Unsupported base"),
}
}
}
impl Error for ParseError {}
#[derive(Debug)]
pub enum DivisionError {
DivisionByZero,
FmtError(fmt::Error),
IoError(io::Error),
ExternalError(Box<dyn Error + Send + Sync>),
}
unsafe impl Sync for DivisionError {}
unsafe impl Send for DivisionError {}
impl fmt::Display for DivisionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DivisionError::DivisionByZero => write!(f, "Division by zero"),
DivisionError::FmtError(e) => write!(f, "Fmt error: {}", e),
DivisionError::IoError(e) => write!(f, "IO error: {}", e),
DivisionError::ExternalError(e) => write!(f, "External error: {}", e),
}
}
}
impl Error for DivisionError {}
impl From<io::Error> for DivisionError {
fn from(error: io::Error) -> DivisionError {
DivisionError::IoError(error)
}
}
impl From<fmt::Error> for DivisionError {
fn from(error: fmt::Error) -> DivisionError {
DivisionError::FmtError(error)
}
}