soph_core/traits/
error.rs

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
32
33
34
35
36
37
38
39
pub trait ErrorTrait {
    fn boxed<E>(error: E) -> crate::BoxError
    where
        E: std::error::Error + Send + Sync + 'static,
    {
        Box::new(error)
    }

    #[cfg(feature = "anyhow")]
    fn anyhow<E>(error: E) -> anyhow::Error
    where
        E: std::error::Error + Send + Sync + 'static,
    {
        anyhow::Error::new(error)
    }

    #[cfg(feature = "eyre")]
    fn eyre<E>(error: E) -> eyre::Report
    where
        E: std::error::Error + Send + Sync + 'static,
    {
        eyre::Report::new(error)
    }

    fn wrap<E>(error: E) -> crate::AnyError
    where
        E: std::error::Error + Send + Sync + 'static,
    {
        cfg_if::cfg_if! {
            if #[cfg(feature = "eyre")]{
                eyre::Report::new(error)
            }else if #[cfg(feature = "anyhow")]{
                anyhow::Error::new(error)
            }else{
               Box::new(error)
            }
        }
    }
}