matreex 0.44.5

A simple matrix implementation.
Documentation
//! Error handling primitives.

/// An alias for [`core::result::Result`] with the error type [`Error`].
pub type Result<T> = core::result::Result<T, Error>;

/// Error kinds.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[non_exhaustive]
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 {}