Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit be2b47e

Browse files
committed
extend README.md
1 parent 95b73fb commit be2b47e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

node/fatality/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ and any unknown annotations will be passed to that.
88

99
## Usage
1010

11-
`fatality` currently only provides a `trait Fatality` with a single `fn is_fatal(&self) -> bool`.
11+
`#[fatality]` currently provides a `trait Fatality` with a single `fn is_fatal(&self) -> bool` by default.
12+
13+
Annotating with `#[fatality(splitabl)]` (which disallows usage of `forward` variant annotations), allows to split the type into two sub-types, a `Jfyi*` and a `Fatal*` one via `fn split(self) -> Result<Self::Jfyi, Self::Fatal>`.
14+
1215

1316
The derive macro implements them, and can defer calls, based on `thiserror` annotations, specifically
1417
`#[source]` and `#[transparent]` on `enum` variants and their members.
@@ -42,6 +45,34 @@ enum OhMy {
4245
}
4346
```
4447

48+
```rust
49+
#[fatality]
50+
enum Yikes {
51+
#[error("An apple a day")]
52+
Orange,
53+
54+
#[fatal]
55+
#[error("So dead")]
56+
Dead,
57+
}
58+
59+
fn foo() -> Result<(), Yikes> {
60+
Err(Yikes::Dead)
61+
}
62+
63+
fn i_call_foo() -> Result<(), FatalYikes> {
64+
// TODO: not yet implemented
65+
let x = foo().fatal_or_log(|jfyi| { log::warn!(..) })?;
66+
}
67+
68+
fn i_call_foo_too() -> Result<(), FatalYikes> {
69+
// implemented
70+
if let Err(e) = foo() {
71+
log::warn!("Jfyi: {:?}", e.split()?);
72+
}
73+
}
74+
```
75+
4576
## Roadmap
4677

4778
* [] Reduce the marco overhead, replace `#[fatal($args)]#[error(..` with `#[fatal($args;..)]` and generate the correct `#[error]` annotations for `thiserror`.

0 commit comments

Comments
 (0)