src/error.rs

Tue, 29 Apr 2025 00:03:12 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 29 Apr 2025 00:03:12 -0500
branch
dev
changeset 104
e7f1cb4bec78
parent 76
99ad55974e62
permissions
-rw-r--r--

Norm222

/*!
Error passing helper types
*/

/// A [`Result`] containing `T` or a dynamic error type
pub type DynResult<T> = Result<T, anyhow::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