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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//! Compatibility and interoperability with other error handling libraries.
//!
//! # Overview
//!
//! This module provides integration with popular error handling libraries in
//! the Rust ecosystem, enabling seamless interoperability and gradual migration
//! paths. Each submodule offers bidirectional conversion traits and utilities
//! for working with rootcause alongside other error handling approaches.
//!
//! # Available Integrations
//!
//! - [`anyhow1`] - Integration with the `anyhow` 1.x error handling library
//! (requires the `compat-anyhow1` feature flag)
//! - [`boxed_error`] - Convert reports to and from boxed error trait objects
//! (`Box<dyn Error>` and `Box<dyn Error + Send + Sync>`)
//! - [`error_stack05`] - Integration with the `error-stack` 0.5.x error
//! handling library (requires the `compat-error-stack05` feature flag)
//! - [`error_stack06`] - Integration with the `error-stack` 0.6.x error
//! handling library (requires the `compat-error-stack06` feature flag)
//! - [`eyre06`] - Integration with the `eyre` 0.6.x error handling library
//! (requires the `compat-eyre06` feature flag)
//!
//! # When to Use Compatibility Modules
//!
//! These compatibility modules are useful when:
//! - **Migrating incrementally**: Gradually adopt rootcause in an existing
//! codebase without rewriting everything at once
//! - **Interoperating with dependencies**: Call libraries that use different
//! error handling approaches from your rootcause-based code
//! - **Mixed codebases**: Work in projects where different parts use different
//! error handling strategies
//! - **Evaluating rootcause**: Try out rootcause features while maintaining
//! compatibility with your existing error handling
//!
//! # Design Philosophy
//!
//! Each compatibility module aims to provide:
//! - **Bidirectional conversions**: Convert errors in both directions to
//! support flexible integration patterns
//! - **Information preservation**: Maintain error context and formatting across
//! conversions where possible
//! - **Ergonomic APIs**: Use familiar Rust patterns like `From`/`Into` traits
//! and extension traits with descriptive method names
//!
//! # Example
//!
//! Here's how to use the [`IntoRootcause`] trait to convert external errors:
//!
//! ```
//! use rootcause::prelude::*;
//!
//! # #[cfg(feature = "compat-anyhow1")] {
//! // Call an anyhow-based function from rootcause code
//! fn legacy_function() -> anyhow::Result<String> {
//! anyhow::bail!("something went wrong");
//! }
//!
//! fn new_function() -> Result<String, Report> {
//! // Convert seamlessly using .into_rootcause()
//! let value = legacy_function().into_rootcause()?;
//! Ok(value)
//! }
//! # }
//! ```
//!
//! The [`IntoRootcause`] trait is available for all supported external error
//! types, making it easy to integrate them with rootcause.
//!
//! See the individual module documentation for detailed integration guides and
//! migration strategies.
use crate::;
/// A trait for converting external error types into rootcause [`Report`]s.
///
/// This trait provides a standardized way to convert errors from other error
/// handling libraries into rootcause reports. It's designed to be implemented
/// by compatibility modules for different error handling libraries.
///
/// The trait provides the `.into_rootcause()` method, which can convert both
/// individual error values and `Result` types. This makes it easy to integrate
/// external error types with rootcause's error handling.
///
/// # When to Use
///
/// Use this trait when you need to:
/// - Call functions that return errors from other libraries while using
/// rootcause for your own error handling
/// - Migrate incrementally from another error handling approach to rootcause
/// - Integrate with dependencies that use different error handling libraries
///
/// # Implementations
///
/// This trait is implemented by compatibility modules for specific error
/// handling libraries:
/// - [`anyhow1`] module provides implementations for [`anyhow::Error`] and
/// [`anyhow::Result<T>`]
/// - [`error_stack05`] and [`error_stack06`] modules provide implementations
/// for [`error_stack::Report<C>`] and `Result<T, error_stack::Report<C>>`
/// - [`eyre06`] module provides implementations for [`eyre::Report`] and
/// [`eyre::Result<T>`]
///
/// [`anyhow::Error`]: ::anyhow::Error
/// [`anyhow::Result<T>`]: ::anyhow::Result
/// [`error_stack::Report<C>`]: ::error_stack::Report
///
/// # Examples
///
/// ```
/// use rootcause::prelude::*;
///
/// # #[cfg(feature = "compat-anyhow1")] {
/// // Converting an anyhow Result to a rootcause Result
/// fn uses_anyhow() -> anyhow::Result<i32> {
/// Ok(42)
/// }
///
/// fn uses_rootcause() -> Result<i32, Report> {
/// let value = uses_anyhow().into_rootcause()?;
/// Ok(value)
/// }
/// # }
/// ```
///
/// ```
/// use rootcause::prelude::*;
///
/// # #[cfg(feature = "compat-anyhow1")] {
/// // Converting an individual error
/// let external_error = anyhow::anyhow!("database connection failed");
/// let report: Report = external_error.into_rootcause();
/// # }
/// ```
/// A wrapper that adapts a rootcause [`Report`] to implement
/// [`core::error::Error`].
///
/// This type is used internally by compatibility modules to convert rootcause
/// reports into error types that can be used with external error handling
/// libraries. It wraps a cloneable, sendable report and delegates formatting
/// and error trait implementations to the underlying report.
///
/// You typically don't need to use this type directly - it's used automatically
/// by conversion traits like [`anyhow1::IntoAnyhow`] and
/// [`error_stack06::IntoErrorStack`].
///
/// # Type Parameters
///
/// - `C`: The context type of the wrapped report
///
/// # Examples
///
/// ```
/// use rootcause::{Report, compat::ReportAsError};
///
/// fn requires_error_trait(err: impl std::error::Error) {}
///
/// let report = Report::new_sendsync(std::io::Error::from(std::io::ErrorKind::NotFound));
/// let as_error = ReportAsError(report.into_cloneable());
/// requires_error_trait(as_error);
/// ```
;