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
40
41
42
43
44
45
#![feature(error_generic_member_access)] // TODO: it's nightly-only

mod as_dyn;
mod backtrace;
mod error_box;
mod report;

pub use as_dyn::AsDyn;
pub use report::{AsReport, Report};
pub use thiserror_ext_derive::{Box, Construct, ContextInto};

#[doc(hidden)]
pub mod __private {
    pub use crate::backtrace::{MaybeBacktrace, NoBacktrace};
    pub use crate::error_box::ErrorBox;
    pub use thiserror;
}

macro_rules! for_dyn_error_types {
    ($macro:ident) => {
        $macro! {
            { dyn std::error::Error },
            { dyn std::error::Error + Send },
            { dyn std::error::Error + Sync },
            { dyn std::error::Error + Send + Sync },
            { dyn std::error::Error + Send + Sync + std::panic::UnwindSafe },
        }
    };
}
pub(crate) use for_dyn_error_types;

pub(crate) mod error_sealed {
    pub trait Sealed {}

    impl<T: std::error::Error> Sealed for T {}

    macro_rules! impl_sealed {
        ($({$ty:ty },)*) => {
            $(
                impl Sealed for $ty {}
            )*
        };
    }
    for_dyn_error_types! { impl_sealed }
}