Skip to main content

Module compat

Module compat 

Source
Expand description

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::*;

// 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.

Modules§

anyhow1compat-anyhow1
Bidirectional integration with the anyhow 1.x error handling library.
boxed_error
Convert rootcause Reports into boxed error trait objects.
error_stack05compat-error-stack05
Bidirectional integration with the error-stack 0.5.x error handling library.
error_stack06compat-error-stack06
Bidirectional integration with the error-stack 0.6.x error handling library.
eyre06compat-eyre06
Bidirectional integration with the eyre 0.6.x error handling library.

Structs§

ReportAsError
A wrapper that adapts a rootcause Report to implement core::error::Error.

Traits§

IntoRootcause
A trait for converting external error types into rootcause Reports.