#[derive(Debug)]
pub struct UnexpectedCharacterError(pub char);
#[derive(Debug)]
pub enum FromFloatError<T> {
NotNormal(T),
Negative(T),
}
#[derive(Debug)]
pub enum DivisionError {
DivisionByZero,
InfiniteNewtonRaphson,
}
impl<T: std::fmt::Display> std::fmt::Display for FromFloatError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
FromFloatError::NotNormal(num) => {
write!(f, "Attempt at converting an abnormal float: {}", num)
}
FromFloatError::Negative(num) => {
write!(f, "Attempt at converting a negative number: {}", num)
}
}
}
}
impl std::fmt::Display for UnexpectedCharacterError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"Got an unexpected character when reading string: {}",
self.0
)
}
}
impl std::fmt::Display for DivisionError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::DivisionByZero => write!(f, "Attempt at division by zero !"),
Self::InfiniteNewtonRaphson => write!(f, "Could not converge to the division result."),
}
}
}