syn-miette

Crates.iosyn-miette
lib.rssyn-miette
version0.3.0
sourcesrc
created_at2023-10-04 03:00:09.105082
updated_at2024-04-08 19:59:39.7555
descriptionA `syn::Error` wrapper that provides pretty diagnostic messages using `miette`.
homepage
repositoryhttps://github.com/aatifsyed/syn-miette
max_upload_size
id991773
size33,936
Aatif Syed (aatifsyed)

documentation

https://docs.rs/syn-miette

README

A [syn::Error] wrapper that provides pretty diagnostic messages using [miette].

Usage

let source = r"
pub struct {
    num_yaks: usize
}";

let error = syn::parse_str::<syn::DeriveInput>(source).unwrap_err();
let error = syn_miette::Error::new(error, source);

assert_eq!(
    error.render(), // only with `--feature render`
"  × expected identifier
   ╭─[2:12]
 1 │
 2 │ pub struct {
   ·            ┬
   ·            ╰── expected identifier
 3 │     num_yaks: usize
   ╰────
"
);

Notably, Error properly renders children that have been [syn::Error::combine]-ed:

  × duplicate definition of `Foo`
   ╭─[1:8]
 1 │ struct Foo;
   ·        ─┬─
   ·         ╰── initial definition here
 2 │ enum Bar {}
 3 │ union Foo {}
   ·       ─┬─
   ·        ╰── duplicate definition of `Foo`
   ╰────
Commit count: 15

cargo fmt