Expand description
Generic diagnostic engine for tools that need rich, rustc-style error output. Plug in your own error code enum, attach spans + labels + suggestions, and render in pretty (color), plain, or JSON modes.
See examples/ for end-to-end demos.
Macros§
- diag
- Shorthand for
Diagnostic::new(...)with optional label/note/help/suggestion.
Structs§
- Diagnostic
- One error / warning / note carrying a code, message, labels, notes, help, and suggestions.
- Diagnostic
Engine - Collects diagnostics, tracks per-severity counts, and renders them in pretty / plain / compact / JSON modes.
- Diagnostic
Formatter - Renders one diagnostic at a time. Holds a borrowed (or owned) line cache
plus the active
RenderOptions. - Label
- A span + optional message + optional per-caret note. Multiple labels per diagnostic stack rustc-style.
- Render
Options - Tunables for rendered output.
- Source
Cache - Pre-split source cache. Build once per source string, reuse for many diagnostics.
- Span
- Source span.
- Suggestion
- Code rewrite suggestion attached to a diagnostic.
Enums§
- Applicability
- How confident the suggestion is — controls whether IDEs may auto-apply it.
- Label
Style - Caret style for a label.
Primaryunderlines with^,Secondarywith-. - Severity
- Severity of a diagnostic.
Traits§
- Diagnostic
Code - Implement this on your error enum to plug into the diagnostic system.
Functions§
- format_
all_ smart - Format every diagnostic in
engineto a single string, picking with-source vs compact rendering per diagnostic. Trailing summary line included. - format_
compact - Render a single diagnostic in compact (source-less) form.
- print_
all_ smart - Print every diagnostic in
engineto stderr, picking with-source vs compact rendering per diagnostic.color = None→ auto-detect viastd::io::stderr().is_terminal(). Trailing summary line included.