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 newReport) - Existing
Reportinstances (performs identity or marker conversion)
§Thread Safety
The type parameter T specifies the desired thread-safety marker:
markers::SendSync: Report can be sent across threadsmarkers::Local: Report is restricted to the current thread
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
ResultExtmethods to add context toResulttypes - Using the
Fromtrait 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);