Skip to main content

Crate rootcause_preformat

Crate rootcause_preformat 

Source
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:

§Why preformat?

  • Regaining mutability: After preformatting, you get back a Mutable report even if the original was Cloneable.
  • Thread safety: Non-Send/Sync error types can be preformatted to produce a Send + Sync report 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§

PreformattedAttachment
An attachment that has been preformatted into Strings for both Display and Debug.
PreformattedContext
A context that has been preformatted into Strings for both Display and Debug.

Traits§

ContextTransformNestedExt
Extension trait providing context_transform_nested on Report with a Mutable root, and on Result<_, Report<_, Mutable, _>>.
PreformatAttachmentExt
Extension trait providing preformat on ReportAttachment, ReportAttachmentRef, and ReportAttachmentMut.
PreformatReportExt
Extension trait providing preformat on Report, ReportRef, and ReportMut.
PreformatRootExt
Extension trait providing preformat_root on Report with a Mutable root.