From 62cfd221ba0f956825886726166095cec6dbd89c Mon Sep 17 00:00:00 2001 From: Yiyu Lin Date: Fri, 23 Feb 2024 23:43:22 +0800 Subject: [PATCH] docs: add `severity` example (#350) Co-authored-by: hzlinyiyu --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 302e0b5e..7e6ff292 100644 --- a/README.md +++ b/README.md @@ -425,7 +425,7 @@ pub struct MyErrorType { } ``` -##### ... help text +#### ... help text `miette` provides two facilities for supplying help text for your errors: The first is the `#[help()]` format attribute that applies to structs or @@ -461,6 +461,19 @@ let err = Foo { }; ``` +#### ... severity level +`miette` provides a way to set the severity level of a diagnostic. + +```rust +use miette::Diagnostic; +use thiserror::Error; + +#[derive(Debug, Diagnostic, Error)] +#[error("welp")] +#[diagnostic(severity(Warning))] +struct Foo; +``` + #### ... multiple related errors `miette` supports collecting multiple errors into a single diagnostic, and @@ -635,7 +648,7 @@ then you may want to use [`miette!`], [`diagnostic!`] macros or let source = "2 + 2 * 2 = 8".to_string(); let report = miette!( - labels = vec[ + labels = vec![ LabeledSpan::at(12..13, "this should be 6"), ], help = "'*' has greater precedence than '+'",