rootcause-preformat
Preformatting support for the rootcause error reporting library.
Overview
This crate provides extension traits that turn a rootcause Report into a version where every context and attachment has been formatted into a String. The result behaves the same way when printed, but the original types have been erased.
Preformatting is useful when you need to:
- Regain mutability. A preformatted report is always
Mutable, even if the input wasCloneable. - Cross thread boundaries. Reports containing
!Send/!Synctypes (e.g. errors that holdRcorCell) becomeSend + Syncafter preformatting. - Freeze the rendered output. The preformatted version always displays the same way, even if the original types or formatting hooks are no longer available.
Quick Start
Add to your Cargo.toml:
[]
= "0.13"
= "0.13"
Bring the extension traits into scope and call .preformat():
use ;
use ;
let report: Report = report!;
let preformatted: = report.preformat;
// The preformatted report displays identically to the original
assert_eq!;
Crossing thread boundaries
use Cell;
use ;
use ;
// Cell is !Send and !Sync
let local: = report!;
// Preformat to obtain a Send + Sync report
let send_sync: = local.preformat;
spawn.join.unwrap;
Provided Extension Traits
PreformatReportExt::preformat— preformat an entire report tree. Implemented forReport,ReportRef, andReportMut.PreformatAttachmentExt::preformat— preformat a single attachment. Implemented forReportAttachment,ReportAttachmentRef, andReportAttachmentMut.PreformatRootExt::preformat_root— extract the typed root context and return a preformatted report alongside it. Useful when you need the typed value for processing and the formatted version for display.ContextTransformNestedExt::context_transform_nested— transform the root context while nesting the original report (preformatted) as a child. Implemented forReport<_, Mutable, _>andResult<_, Report<_, Mutable, _>>.
API Documentation
For complete API documentation, see docs.rs/rootcause-preformat.
Minimum Supported Rust Version (MSRV)
This crate's MSRV matches rootcause: 1.89.0