Expand description
Preformatting extensions for rootcause error reports.
This crate adds the ability to turn a Report into a version where every
context and attachment has been formatted into a String and the original
types have been erased. The two storage types (PreformattedContext and
PreformattedAttachment) plus a handful of extension traits are exposed:
PreformatReportExt::preformat— preformat an entire report tree.PreformatAttachmentExt::preformat— preformat a single attachment.PreformatRootExt::preformat_root— extract the typed root context and return a preformatted report alongside it.ContextTransformNestedExt::context_transform_nested— transform the root context while nesting the original report as a preformatted child.
§Why preformat?
- Regaining mutability: After preformatting, you get back a
Mutablereport even if the original wasCloneable. - Thread safety: Non-
Send/Syncerror types can be preformatted to produce aSend + Syncreport that can cross thread boundaries. - Preserving formatting: The preformatted version will always display the same way, even if the original types or hooks are no longer available.
§Quick Start
use rootcause::{
markers::{Mutable, SendSync},
prelude::*,
};
use rootcause_preformat::{PreformatReportExt, PreformattedContext};
let report: Report = report!("database connection failed");
let preformatted: Report<PreformattedContext, Mutable, SendSync> = report.preformat();
// The preformatted report displays identically to the original
assert_eq!(format!("{}", report), format!("{}", preformatted));Structs§
- Preformatted
Attachment - An attachment that has been preformatted into
Strings for bothDisplayandDebug. - Preformatted
Context - A context that has been preformatted into
Strings for bothDisplayandDebug.
Traits§
- Context
Transform Nested Ext - Extension trait providing
context_transform_nestedonReportwith aMutableroot, and onResult<_, Report<_, Mutable, _>>. - Preformat
Attachment Ext - Extension trait providing
preformatonReportAttachment,ReportAttachmentRef, andReportAttachmentMut. - Preformat
Report Ext - Extension trait providing
preformatonReport,ReportRef, andReportMut. - Preformat
Root Ext - Extension trait providing
preformat_rootonReportwith aMutableroot.