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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use Backtrace;
use Error as StdError;
use async_trait;
/// An async-compatible version of the ForgeError trait.
///
/// This trait extends the standard error capabilities with async support,
/// allowing for async error handling in futures and async functions.
///
/// # Example
///
/// Requires the `async` cargo feature (which pulls in `async-trait`).
/// The hidden `#[cfg(feature = "async")]` gate means this doctest is
/// only compiled when the feature is enabled — when running
/// `cargo test --all-features` it executes normally, and when the
/// feature is off it is silently skipped.
///
/// ```
/// # #[cfg(feature = "async")] {
/// use error_forge::async_error::AsyncForgeError;
/// use async_trait::async_trait;
/// use std::error::Error as StdError;
///
/// #[derive(Debug)]
/// struct MyAsyncError { message: String }
///
/// impl std::fmt::Display for MyAsyncError {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// write!(f, "{}", self.message)
/// }
/// }
///
/// impl std::error::Error for MyAsyncError {}
///
/// #[async_trait]
/// impl AsyncForgeError for MyAsyncError {
/// fn kind(&self) -> &'static str { "AsyncExample" }
/// fn caption(&self) -> &'static str { "Async Example Error" }
///
/// async fn async_handle(&self) -> Result<(), Box<dyn StdError + Send + Sync>> {
/// Ok(())
/// }
/// }
/// # }
/// ```
/// Type alias for async error-forge results.
pub type AsyncResult<T, E> = Result;