rstmt_nrt/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: @FL03
4*/
5
6#[cfg(feature = "alloc")]
7use alloc::boxed::Box;
8
9/// a type alias for a [`Result`](core::result::Result) with [`TriadError`] as its error type.
10pub(crate) type Result<T = ()> = core::result::Result<T, TriadError>;
11
12/// the [`TriadError`] type enumerates the various errors that one can expect to encounter
13/// within the crate.
14#[derive(Debug, thiserror::Error)]
15pub enum TriadError {
16    #[error("Invalid triad")]
17    InvalidTriad,
18    #[error("Invalid Triad Class")]
19    InvalidTriadClass,
20    #[error(transparent)]
21    #[cfg(feature = "alloc")]
22    CoreError(#[from] rstmt::Error),
23    #[error(transparent)]
24    GraphError(#[from] rshyper::Error),
25}
26
27#[cfg(feature = "alloc")]
28impl From<TriadError> for rstmt::Error {
29    fn from(err: TriadError) -> Self {
30        use TriadError::*;
31        match err {
32            CoreError(e) => e,
33            _ => rstmt::Error::BoxError(Box::new(err)),
34        }
35    }
36}
37
38#[cfg(feature = "alloc")]
39impl From<&str> for TriadError {
40    fn from(err: &str) -> Self {
41        rstmt::Error::from(err).into()
42    }
43}
44
45#[cfg(feature = "alloc")]
46impl From<String> for TriadError {
47    fn from(err: String) -> Self {
48        rstmt::Error::from(err).into()
49    }
50}