src/error.rs

Fri, 13 Dec 2024 22:37:12 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 13 Dec 2024 22:37:12 -0500
branch
dev
changeset 57
1b3b1687b9ed
parent 5
59dc4c5883f4
child 76
99ad55974e62
permissions
-rw-r--r--

Add direct products (Pair, RowOp, ColOp, DiagOp)

/*!
Error passing helper types
*/

use std::error::Error;

/// A [`Result`] containing `T` or a dynamic error type
pub type DynResult<T> = Result<T, Box<dyn Error>>;

/// A [`Result`] containing `()` or a dynamic error type
pub type DynError = DynResult<()>;

#[derive(Clone, Debug)]
/// Type for numerical errors.
pub struct NumericalError(
    /// Provides additional information about the error
    pub &'static str
);

impl std::fmt::Display for NumericalError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.0 {
            "" => write!(f, "Numerical error"),
            s => write!(f, "{s}"),
        }
    }
}

impl std::error::Error for NumericalError {}

mercurial