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
use cxx::Exception;
use thiserror::Error;

/// Error struct that wraps all exceptions thrown by the LHAPDF library.
#[derive(Debug, Error)]
pub enum Error {
    /// Captures an exception coming from the C++ LHAPDF library.
    #[error(transparent)]
    LhapdfException(Exception),
    /// General error with a message.
    #[error("{0}")]
    General(String),
    /// Errors from within this library.
    #[error(transparent)]
    Other(anyhow::Error),
}

/// Type definition for results with an [`enum@Error`].
pub type Result<T> = std::result::Result<T, Error>;

impl From<Exception> for Error {
    fn from(err: Exception) -> Self {
        Self::LhapdfException(err)
    }
}

impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Self {
        Self::Other(anyhow::Error::new(err))
    }
}