managed_lhapdf/
error.rs

1use cxx::Exception;
2use thiserror::Error;
3
4/// Error struct that wraps all exceptions thrown by the LHAPDF library.
5#[derive(Debug, Error)]
6pub enum Error {
7    /// Captures an exception coming from the C++ LHAPDF library.
8    #[error(transparent)]
9    LhapdfException(Exception),
10    /// General error with a message.
11    #[error("{0}")]
12    General(String),
13    /// Errors from within this library.
14    #[error(transparent)]
15    Other(anyhow::Error),
16}
17
18/// Type definition for results with an [`enum@Error`].
19pub type Result<T> = std::result::Result<T, Error>;
20
21impl From<Exception> for Error {
22    fn from(err: Exception) -> Self {
23        Self::LhapdfException(err)
24    }
25}
26
27impl From<std::io::Error> for Error {
28    fn from(err: std::io::Error) -> Self {
29        Self::Other(anyhow::Error::new(err))
30    }
31}