use std::error::Error as StdError;
use std::fmt::{Debug, Display, Formatter};
use crate::SignedNum;
#[derive(PartialEq)]
pub enum Error<'a, T> {
InvalidOrMissingAxis(&'a str),
InvalidX(T,T),
InvalidY(T,T),
InvalidZ(T,T),
MissingPoint(&'a str),
}
impl<T: SignedNum> Error<'_, T> {
fn message(&self) -> String {
use Error::*;
match self {
InvalidOrMissingAxis(axis) => format!("Invalid axis. This BresenhamZip only accepts: {axis:?}"),
InvalidX(left, right) => format!("Invalid X. Both values must have the same X ({left:?} != {right:?})"),
InvalidY(left, right) => format!("Invalid Y. Both values must have the same Y ({left:?} != {right:?})"),
InvalidZ(left, right) => format!("Invalid Z. Both values must have the same Z ({left:?} != {right:?})"),
MissingPoint(point) => format!("Missing point. You must specify the {point:?}"),
}
}
}
impl<T: SignedNum> Debug for Error<'_, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message())
}
}
impl<T: SignedNum> Display for Error<'_, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message())
}
}
impl<T: SignedNum> StdError for Error<'_, T> {}