Skip to main content

garde_errors_to_miette

Function garde_errors_to_miette 

Source
pub fn garde_errors_to_miette<T>(
    spanned: &Spanned<T>,
    errors: &Report,
    source: &str,
    name: impl Into<String>,
) -> Report
Expand description

Render a [garde::Report] tree against a Spanned<T> payload as a [miette::Report].

The error message is the compact single-line summary garde’s own walker produces (path → message pairs joined with ;); the source label points at the supplied Spanned<T>’s byte range. name is the source identifier shown in the report header (typically a filename).

§Examples

ⓘ
use noyalib::Spanned;
use noyalib::validated_miette::garde_errors_to_miette;
use garde::Validate;

#[derive(Debug, serde::Deserialize, Validate)]
struct Cfg {
    #[garde(range(min = 1024))]
    port: u16,
}

let yaml = "port: 22\n";
let wrapped: Spanned<Cfg> = noyalib::from_str(yaml).unwrap();
if let Err(errs) = wrapped.value.validate() {
    let report = garde_errors_to_miette(&wrapped, &errs, yaml, "config.yaml");
    // `report.to_string()` carries the rendered diagnostic.
    drop(report);
}