rstmt_nrt/
error.rs

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