concision_core/error/
kinds.rs

1/*
2   Appellation: kinds <module>
3   Contrib: FL03 <jo3mccain@icloud.com>
4*/
5pub use self::{external::*, predict::*};
6
7mod external;
8mod predict;
9
10use crate::nn::ModelError;
11use strum::{AsRefStr, Display, EnumCount, EnumIs, VariantNames};
12
13#[derive(
14    AsRefStr,
15    Clone,
16    Debug,
17    Display,
18    EnumCount,
19    EnumIs,
20    Eq,
21    Hash,
22    Ord,
23    PartialEq,
24    PartialOrd,
25    VariantNames,
26)]
27#[cfg_attr(
28    feature = "serde",
29    derive(serde::Deserialize, serde::Serialize),
30    serde(rename_all = "lowercase", tag = "kind")
31)]
32#[strum(serialize_all = "lowercase")]
33pub enum ErrorKind {
34    IO,
35    External(ExternalError),
36    Predict(PredictError),
37    Model(ModelError),
38    Shape(String),
39}
40
41macro_rules! from_err {
42    ($S:ty: $($($p:ident)::*($err:ty)),* $(,)*) => {
43        $(
44            from_err!(@impl $S: $($p)::*($err));
45        )*
46    };
47    (@impl $S:ty: $($p:ident)::*($err:ty)) => {
48        impl From<$err> for $S {
49            fn from(err: $err) -> Self {
50                $($p)::*(err)
51            }
52        }
53    };
54}
55
56from_err!(ErrorKind:
57    ErrorKind::External(ExternalError),
58    ErrorKind::Model(ModelError),
59    ErrorKind::Predict(PredictError),
60);