1#![warn(missing_docs)]
3
4use std::fmt::{Display, Formatter, Result};
5
6#[derive(Debug, PartialEq)]
7pub enum MatrixError {
9 MatrixCreationError,
11 MatrixIndexOutOfBoundsError,
13 MatrixMultiplicationDimensionMismatchError,
16 MatrixDimensionMismatchError,
19 MatrixConcatinationError,
21 MatrixParseError,
24 MatrixDivideByZeroError,
26 MatrixFileReadError(&'static str),
28}
29
30impl Display for MatrixError {
31 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
32 match self {
33 MatrixError::MatrixCreationError => {
34 write!(f, "There was an error creating the matrix.")
35 }
36 MatrixError::MatrixIndexOutOfBoundsError => {
37 write!(f, "The indexes are out of bounds for the matrix")
38 }
39 MatrixError::MatrixMultiplicationDimensionMismatchError => {
40 write!(
41 f,
42 "The two matrices supplied are not on the form M x N @ N x P"
43 )
44 }
45 MatrixError::MatrixDimensionMismatchError => {
46 write!(f, "The matrixs provided are both not on the form M x N")
47 }
48
49 MatrixError::MatrixConcatinationError => {
50 write!(
51 f,
52 "Matrixs could not be concatinated or extended due to more than 1 dim mismatch"
53 )
54 }
55 MatrixError::MatrixParseError => write!(f, "Failed to parse matrix from file"),
56 MatrixError::MatrixDivideByZeroError => write!(f, "Tried to divide by zero"),
57 MatrixError::MatrixFileReadError(path) => {
58 write!(f, "Could not read file from path: {}", path)
59 }
60 }
61 }
62}