Skip to main content

IntoReport

Trait IntoReport 

Source
pub trait IntoReport<T> {
    type Context: ?Sized + 'static;
    type Ownership: 'static;

    // Required method
    fn into_report(self) -> Report<Self::Context, Self::Ownership, T>;
}
Expand description

Converts errors and reports into Report instances with specific thread-safety markers.

This trait is primarily used internally by the rootcause library for trait bounds in extension methods like ResultExt. While it’s available for direct use, most applications will find the report! macro more convenient for creating reports.

§Internal Usage

This trait enables generic conversions in methods like Result::context, allowing them to accept various error types and convert them uniformly into reports.

§Automatic Implementations

This trait is automatically implemented for:

  • All types implementing std::error::Error (converts to new Report)
  • Existing Report instances (performs identity or marker conversion)

§Thread Safety

The type parameter T specifies the desired thread-safety marker:

When converting from SendSync to Local, the conversion always succeeds. Converting from Local to SendSync is only available if the context type is Send + Sync.

§Typical Usage

Most applications won’t need to call this trait directly. Instead, consider:

  • Using report! to create reports from errors or strings
  • Using ResultExt methods to add context to Result types
  • Using the From trait for generic type conversions

§Examples

Direct usage is possible, though the alternatives above are often more ergonomic:

use std::io;

use rootcause::{IntoReport, prelude::*};

// Direct usage
let error: io::Error = io::Error::new(io::ErrorKind::NotFound, "file not found");
let report: Report<io::Error> = error.into_report();

// Alternative using the macro (often more convenient)
let error2: io::Error = io::Error::new(io::ErrorKind::NotFound, "config.toml");
let report2: Report<io::Error> = report!(error2);

Required Associated Types§

Source

type Context: ?Sized + 'static

The context type of the resulting report.

Source

type Ownership: 'static

The ownership marker of the resulting report.

Required Methods§

Source

fn into_report(self) -> Report<Self::Context, Self::Ownership, T>

Converts self into a Report with the specified thread-safety marker.

Most applications will find the report! macro more convenient for creating reports.

Implementors§

Source§

impl<C, T> IntoReport<T> for C
where C: ObjectMarkerFor<T> + Error + Sized + 'static,

Source§

impl<C: ?Sized, O> IntoReport<SendSync> for Report<C, O, SendSync>

Source§

impl<C: ?Sized, O, T> IntoReport<Local> for Report<C, O, T>