#[derive(Debug, PartialEq)]
pub enum MatrixError {
IncompatibleSizeError((usize, usize), usize),
IncompatibleShape((usize, usize), (usize, usize)),
OutOfBoundary(usize, usize),
DividedByZero,
IncompatibleFormat(String, &'static str),
NoDivision(&'static str),
}
impl std::error::Error for MatrixError {}
impl std::fmt::Display for MatrixError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MatrixError::IncompatibleSizeError((required_row, required_col), real) => write!(
f,
"incompatible size while require ({:?} x {:?}) but the real size is {:?}",
required_row, required_col, real
),
MatrixError::IncompatibleShape(required, real) => {
write!(
f,
"incompatible shape while require {:?} but the real shape is {:?}",
required, real
)
}
MatrixError::OutOfBoundary(row, col) => {
write!(f, "out of boundary at ({:?}, {:?})", row, col)
}
MatrixError::DividedByZero => write!(f, "can not divide by zero"),
MatrixError::IncompatibleFormat(from, type_name) => {
write!(f, "can not read {:?} into {:?}", from, type_name)
}
MatrixError::NoDivision(type_name) => {
write!(f, "no proper division can do with {:?}", type_name)
}
}
}
}