doc: extend README.md with display formats

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2023-07-28 17:06:57 +02:00
parent 46b7f58e72
commit 9e03541ac1
Signed by: harald
GPG key ID: 900F3C4971086004

View file

@ -90,6 +90,81 @@ Along with the `Error<T>` struct, `chainerror` comes with some useful helper mac
Debug information is worth it!
## Multiple Output Formats
`chainerror` supports multiple output formats, which can be selected with the different format specifiers:
* `{}`: Display
```text
func1 error calling func2
```
* `{:#}`: Alternative Display
```text
func1 error calling func2
Caused by:
func2 error: calling func3
Caused by:
(passed error)
Caused by:
Error reading 'foo.txt'
Caused by:
entity not found
```
* `{:?}`: Debug
```text
examples/example.rs:50:13: func1 error calling func2
Caused by:
examples/example.rs:25:13: Func2Error(func2 error: calling func3)
Caused by:
examples/example.rs:18:13: (passed error)
Caused by:
examples/example.rs:13:18: Error reading 'foo.txt'
Caused by:
Kind(NotFound)
```
* `{:#?}`: Alternative Debug
```text
Error<example::Func1Error> {
occurrence: Some(
"examples/example.rs:50:13",
),
kind: func1 error calling func2,
source: Some(
Error<example::Func2Error> {
occurrence: Some(
"examples/example.rs:25:13",
),
kind: Func2Error(func2 error: calling func3),
source: Some(
Error<chainerror::AnnotatedError> {
occurrence: Some(
"examples/example.rs:18:13",
),
kind: (passed error),
source: Some(
Error<alloc::string::String> {
occurrence: Some(
"examples/example.rs:13:18",
),
kind: "Error reading 'foo.txt'",
source: Some(
Kind(
NotFound,
),
),
},
),
},
),
},
),
}
```
## Tutorial
Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html)