Skip to content

Commit ed20998

Browse files
authored
feat: support tuple structs and enum variants
Makes #[add_meta] and #derive(Error)] support tuple structs.
2 parents 5e50fb8 + 69df266 commit ed20998

File tree

3 files changed

+425
-164
lines changed

3 files changed

+425
-164
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
A error library that supports tracking the call-site location of errors. Also features an anyhow-style `AnyError`.
66

7-
Usage
8-
97
```rust
108
use n0_error::{e, add_meta, Error, Result, StackResultExt, StdResultExt};
119

@@ -66,4 +64,20 @@ fn main() -> Result<()> {
6664
}
6765
Ok(())
6866
}
67+
68+
// You can also use the macros with tuple structs or enums.
69+
// In this case the meta field will be added as the last field.
70+
71+
#[add_meta]
72+
#[derive(Error)]
73+
#[display("tuple fail ({_0})")]
74+
struct TupleStruct(u32);
75+
76+
#[add_meta]
77+
#[derive(Error)]
78+
enum TupleEnum {
79+
#[display("io failed")]
80+
Io(#[error(source, std_err)] std::io::Error),
81+
}
82+
6983
```

0 commit comments

Comments
 (0)