Skip to main content

error_stack/compat/
mod.rs

1//! Compatibility module to convert errors from other libraries into [`Report`].
2//!
3//! In order to convert these error types, use [`IntoReportCompat::into_report()`].
4
5use crate::Report;
6
7#[cfg(feature = "anyhow")]
8mod anyhow;
9#[cfg(feature = "eyre")]
10mod eyre;
11
12/// Compatibility trait to convert from external libraries to [`Report`].
13///
14/// **Note**: Most error libraries don't implement [`Error`], so it's not possible to directly
15/// convert them to [`Report`]. However, `error-stack` supports converting errors generated from the
16/// [`anyhow`] or [`eyre`] crate via [`IntoReportCompat`].
17///
18/// [`eyre`]: ::eyre
19/// [`anyhow`]: ::anyhow
20/// [`Error`]: core::error::Error
21pub trait IntoReportCompat: Sized {
22    /// Type of the [`Ok`] value in the [`Result`].
23    type Ok;
24
25    /// Type of the resulting [`Err`] variant wrapped inside a [`Report<E>`].
26    ///
27    /// [`Report<E>`]: crate::Report
28    type Err;
29
30    /// Converts the [`Err`] variant of the [`Result`] to a [`Report`].
31    ///
32    /// [`Report`]: crate::Report
33    fn into_report(self) -> Result<Self::Ok, Report<Self::Err>>;
34}