|
1 | | -# `error-stack-macros2` v0.1.0 |
| 1 | +# `error-stack-macros2` v0.2.0 |
2 | 2 |
|
3 | | -The very first development version of `error-stack-macros2` is finally here! |
| 3 | +We have a new development version of `error-stack-macros2`! |
4 | 4 |
|
5 | | -## Features |
| 5 | +## Fixes |
6 | 6 |
|
7 | | -This version (0.1.0) offers a derive macro for the [`Error`](https://doc.rust-lang.org/stable/core/error/trait.Error.html) trait which encourages the best practices for defining [`error-stack`](https://crates.io/crates/error-stack) context types. |
| 7 | +This version (0.2.0) adds support for generics and external attributes to the [`impl_error_stack`](https://docs.rs/error-stack-macros2/latest/error_stack_macros2/derive.Error.html) macro. |
8 | 8 |
|
9 | | -Here's an example. This code: |
| 9 | +This means that types like this: |
10 | 10 |
|
11 | 11 | ```rust |
12 | | -use std::{ |
13 | | - error::Error, |
14 | | - fmt::{self, Display, Formatter}, |
15 | | -}; |
16 | | - |
17 | | -#[derive(Debug)] |
18 | | -pub enum CreditCardError { |
19 | | - InvalidInput(String), |
20 | | - Other, |
21 | | -} |
22 | | - |
23 | | -impl Display for CreditCardError { |
24 | | - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
25 | | - let msg = match self { |
26 | | - Self::InvalidInput(_) => "credit card not found", |
27 | | - Self::Other => "failed to retrieve credit card", |
28 | | - }; |
| 12 | +use error_stack_macros2::Error; |
29 | 13 |
|
30 | | - f.write_str(msg) |
31 | | - } |
| 14 | +#[derive(Debug, Error)] |
| 15 | +#[display("failed to retrieve credit card")] |
| 16 | +enum CreditCardError<T> |
| 17 | +where |
| 18 | + T: Display |
| 19 | +{ |
| 20 | + InvalidInput(T), |
| 21 | + Other |
32 | 22 | } |
33 | 23 |
|
34 | | -impl Error for CreditCardError {} |
| 24 | +#[derive(Debug, Error)] |
| 25 | +#[display("invalid card string")] |
| 26 | +#[allow(non_camel_case_types)] |
| 27 | +struct parseCardError; |
35 | 28 | ``` |
36 | 29 |
|
37 | | -...can now be reduced to this code: |
| 30 | +...can now compile properly. |
38 | 31 |
|
39 | | -```rust |
40 | | -use error_stack_macros2::Error; |
| 32 | +## Performance |
41 | 33 |
|
42 | | -#[derive(Debug, Error)] |
43 | | -pub enum CreditCardError { |
44 | | - #[display("credit card not found")] |
45 | | - InvalidInput(String), |
| 34 | +The entire source code has been refactored to eliminate unnecessary allocations, cloning, and double iterator consumptions. This should make compile times faster and reduce memory usage. |
46 | 35 |
|
47 | | - #[display("failed to retrieve credit card")] |
48 | | - Other, |
49 | | -} |
50 | | -``` |
| 36 | +## Dependencies |
51 | 37 |
|
52 | | -This new release also means that we will now be listening to feedback and accepting new features (macros, obviously). We are also now committed to maintaining this macro going forward and keeping our dependencies up to date. |
| 38 | +As promised, all dependencies have been updated to their latest versions, which in this case means performance improvements and bug fixes. |
53 | 39 |
|
54 | 40 | ## Previous release notes |
55 | 41 |
|
|
0 commit comments