src/error.rs

Tue, 06 Dec 2022 08:29:13 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 06 Dec 2022 08:29:13 +0200
changeset 14
f5b9f4bf25a7
parent 5
59dc4c5883f4
permissions
-rw-r--r--

cargo-d alias generation with a cargo-d script

/*!
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