1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Error handling for this crate.
/// An alias for [`core::result::Result`].
pub type Result<T> = core::result::Result<T, Error>;
/// An enum for error types.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum Error {
/// Error when the size exceeds [`usize::MAX`].
SizeOverflow,
/// Error when the size of the shape does not match the length of
/// the underlying data.
SizeMismatch,
/// Error when attempting to allocate more than [`isize::MAX`] bytes
/// of memory.
///
/// See [`vec`] and *[The Rustonomicon]* for more information.
///
/// [`vec`]: mod@alloc::vec
/// [The Rustonomicon]: https://doc.rust-lang.org/stable/nomicon/vec/vec-alloc.html#allocating-memory
CapacityOverflow,
/// Error when converting a matrix from rows or columns that have
/// inconsistent lengths.
LengthInconsistent,
/// Error when the index is out of bounds.
IndexOutOfBounds,
/// Error when the shapes of two matrices are not conformable for
/// the intended operation.
ShapeNotConformable,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let content = match self {
Self::SizeOverflow => "size overflow",
Self::SizeMismatch => "size mismatch",
Self::CapacityOverflow => "capacity overflow",
Self::LengthInconsistent => "length inconsistent",
Self::IndexOutOfBounds => "index out of bounds",
Self::ShapeNotConformable => "shape not conformable",
};
f.write_str(content)
}
}
impl core::error::Error for Error {}