pub trait FormatRustcStyle {
// Required method
fn format_rustc_style(
&self,
source_code: &str,
filename: &str,
start_line: u32,
renderer: &Renderer,
) -> String;
}Expand description
Extension trait that adds rustc-style formatting to anyhow::Error.
Import this trait to call .format_rustc_style(...) directly on an anyhow::Error.
If the error carries a SpanContext (added during op execution with the
span-diagnostics feature), the output includes a source-location annotation.
Otherwise it falls back to self.to_string().
§Examples
use annotate_snippets::Renderer;
use cel_parser::FormatRustcStyle;
let err = anyhow::anyhow!("something went wrong");
let output = err.format_rustc_style("1 + 2", "example.cel", 1, &Renderer::plain());
assert_eq!(output, "something went wrong");Required Methods§
Sourcefn format_rustc_style(
&self,
source_code: &str,
filename: &str,
start_line: u32,
renderer: &Renderer,
) -> String
fn format_rustc_style( &self, source_code: &str, filename: &str, start_line: u32, renderer: &Renderer, ) -> String
Formats in rustc diagnostic style.
If the error carries a SpanContext, produces a multi-line caret diagnostic.
Otherwise returns self.to_string().
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".