arr_rs/errors/
mod.rs

1/// prelude module - imports facade
2pub mod prelude;
3
4/// `ArrayError` definition - errors that can be returned by the library
5#[derive(Debug, Clone, PartialOrd, PartialEq, Eq)]
6pub enum ArrayError {
7    /// Shape of two arrays must match for broadcast operation
8    BroadcastShapeMismatch,
9    /// Shape of two arrays must match for concatenate operation
10    ConcatenateShapeMismatch,
11    /// Shape mismatching the length of values to build the array from
12    ShapeMustMatchValuesLength,
13    /// Shape of two arrays must match
14    ShapesMustMatch {
15        /// first shape to match
16        shape_1: Vec<usize>,
17        /// second shape to match
18        shape_2: Vec<usize>,
19    },
20    /// Axis to perform squeeze on must have a size of one
21    SqueezeShapeOfAxisMustBeOne,
22    /// `axis` is out of array's bounds
23    AxisOutOfBounds,
24    /// `value` is out of bounds
25    OutOfBounds {
26        /// out of bounds value
27        value: &'static str,
28    },
29    /// Input parameter doesn't match the criteria
30    ParameterError {
31        /// mismatching parameter
32        param: &'static str,
33        /// parameter error message
34        message: &'static str,
35    },
36    /// Not defined for given dimension of input array
37    UnsupportedDimension {
38        /// supported dimensions
39        supported: Vec<usize>,
40    },
41    /// Collection must contain unique elements
42    MustBeUnique {
43        /// value
44        value: String,
45    },
46    /// Values must be equal
47    MustBeEqual {
48        /// value 1
49        value1: String,
50        /// value 2
51        value2: String,
52    },
53    /// Values must be at least
54    MustBeAtLeast {
55        /// value 1
56        value1: String,
57        /// value 2
58        value2: String,
59    },
60    /// Values must be one of
61    MustBeOneOf {
62        /// value 1
63        value1: String,
64        /// value 2
65        value2: String,
66    },
67    /// Function is not implemented
68    NotImplemented,
69    /// Matrix is singular
70    SingularMatrix,
71}
72
73impl std::error::Error for ArrayError {}
74
75impl std::fmt::Display for ArrayError {
76    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77        match self {
78            Self::BroadcastShapeMismatch => write!(f, "Incompatible shapes for broadcasting"),
79            Self::ConcatenateShapeMismatch => write!(f, "Incompatible shapes for concatenate"),
80            Self::ShapeMustMatchValuesLength => write!(f, "Shape must match values length"),
81            Self::ShapesMustMatch { shape_1, shape_2 } => write!(f, "Shapes of {shape_1:?} and {shape_2:?} must match"),
82            Self::SqueezeShapeOfAxisMustBeOne => write!(f, "cannot select an axis to squeeze out which has size not equal to one"),
83            Self::AxisOutOfBounds => write!(f, "`axis` is out of bounds for array"),
84            Self::OutOfBounds { value } => write!(f, "`{value}` is out of bounds"),
85            Self::ParameterError { param, message } => write!(f, "parameter error: `{param}`: {message}"),
86            Self::UnsupportedDimension { supported } => write!(f, "supported dimensions are: {supported:?}"),
87            Self::MustBeUnique { value } => write!(f, "`{value}` must be unique"),
88            Self::MustBeEqual { value1, value2 } => write!(f, "`{value1}` and `{value2}` must be equal"),
89            Self::MustBeAtLeast { value1, value2 } => write!(f, "`{value1}` must be at least `{value2}`"),
90            Self::MustBeOneOf { value1, value2 } => write!(f, "`{value1}` must be one of `{value2}`"),
91            Self::NotImplemented => write!(f, "not implemented"),
92            Self::SingularMatrix => write!(f, "matrix is singular"),
93        }
94    }
95}