docs: add `severity` example (#350)

Co-authored-by: hzlinyiyu <hzlinyiyu@corp.netease.com>
This commit is contained in:
Yiyu Lin 2024-02-23 23:43:22 +08:00 committed by GitHub
parent 328bf37922
commit 62cfd221ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 2 deletions

View File

@ -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 '+'",