docs: add docs for #[related]

This commit is contained in:
Kat Marchán 2021-09-26 12:55:30 -07:00
parent 47e4d4d05c
commit c337e2759f
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 21 additions and 0 deletions

View File

@ -41,6 +41,7 @@ and such might not want.
- [... in `main()`](#-in-main) - [... in `main()`](#-in-main)
- [... diagnostic code URLs](#-diagnostic-code-urls) - [... diagnostic code URLs](#-diagnostic-code-urls)
- [... snippets](#-snippets) - [... snippets](#-snippets)
- [... multiple related errors](#-multiple-related-errors)
- [... handler options](#-handler-options) - [... handler options](#-handler-options)
- [Acknowledgements](#acknowledgements) - [Acknowledgements](#acknowledgements)
- [License](#license) - [License](#license)
@ -354,6 +355,26 @@ pub struct MyErrorType {
} }
``` ```
### ... multiple related errors
`miette` supports collecting multiple errors into a single diagnostic, and
printing them all together nicely.
To do so, use the `#[related]` tag on any `IntoIter` field in your
`Diagnostic` type:
```rust
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Error, Diagnostic)]
#[error("oops")]
struct MyError {
#[related]
Vec<MyError>,
}
```
### ... handler options ### ... handler options
[MietteHandler] is the default handler, and is very customizable. In most [MietteHandler] is the default handler, and is very customizable. In most