ayun_core/traits/
error.rs1pub trait ErrorTrait {
2 fn boxed<E>(error: E) -> crate::BoxError
3 where
4 E: std::error::Error + Send + Sync + 'static,
5 {
6 Box::new(error)
7 }
8
9 #[cfg(feature = "anyhow")]
10 fn anyhow<E>(error: E) -> anyhow::Error
11 where
12 E: std::error::Error + Send + Sync + 'static,
13 {
14 anyhow::Error::new(error)
15 }
16
17 #[cfg(feature = "eyre")]
18 fn eyre<E>(error: E) -> eyre::Report
19 where
20 E: std::error::Error + Send + Sync + 'static,
21 {
22 eyre::Report::new(error)
23 }
24
25 fn wrap<E>(error: E) -> crate::AnyError
26 where
27 E: std::error::Error + Send + Sync + 'static,
28 {
29 cfg_if::cfg_if! {
30 if #[cfg(feature = "eyre")]{
31 eyre::Report::new(error)
32 }else if #[cfg(feature = "anyhow")]{
33 anyhow::Error::new(error)
34 }else{
35 Box::new(error)
36 }
37 }
38 }
39}