Skip to content

Commit f0b62a5

Browse files
authored
Bump to 0.2.4 (#43)
* Bump to 0.2.4 * Update readme
1 parent a0a7083 commit f0b62a5

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased] - ReleaseDate
1010

11+
# [0.2.4] - 2022-05-02
12+
13+
## Added
14+
- Updated `syn` dependency to 2.0
15+
- Support for empty enums
16+
- Implicitly require fmt::Display on all type parameters unless overridden
17+
18+
## Changed
19+
- Bumped MSRV to 1.56
20+
1121
# [0.2.3] - 2021-07-16
1222
## Added
1323
- Added `#[displaydoc("..")]` attribute for overriding a doc comment
@@ -32,7 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3242
lines are needed.
3343

3444
<!-- next-url -->
35-
[Unreleased]: https://github.com/yaahc/displaydoc/compare/v0.2.3...HEAD
45+
[Unreleased]: https://github.com/yaahc/displaydoc/compare/v0.2.4...HEAD
46+
[0.2.4]: https://github.com/yaahc/displaydoc/compare/v0.2.3...v0.2.4
3647
[0.2.3]: https://github.com/yaahc/displaydoc/compare/v0.2.2...v0.2.3
3748
[0.2.2]: https://github.com/yaahc/displaydoc/compare/v0.2.1...v0.2.2
3849
[0.2.1]: https://github.com/yaahc/displaydoc/compare/v0.2.0...v0.2.1

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "displaydoc"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
authors = ["Jane Lusby <[email protected]>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ displaydoc = "0.2"
2020

2121
### Example
2222

23+
*Demonstration alongside the [`Error`][std::error::Error] derive macro from [`thiserror`](https://docs.rs/thiserror/1.0.25/thiserror/index.html),
24+
to propagate source locations from [`io::Error`][std::io::Error] with the `#[source]` attribute:*
2325
```rust
2426
use std::io;
2527
use displaydoc::Display;
@@ -39,22 +41,36 @@ pub enum DataStoreError {
3941
/// unknown data store error
4042
Unknown,
4143
}
44+
45+
let error = DataStoreError::Redaction("CLASSIFIED CONTENT".to_string());
46+
assert!("the data for key `CLASSIFIED CONTENT` is not available" == &format!("{}", error));
4247
```
48+
*Note that although [`io::Error`][std::io::Error] implements `Display`, we do not add it to the
49+
generated message for `DataStoreError::Disconnect`, since it is already made available via
50+
`#[source]`. See further context on avoiding duplication in error reports at the rust blog
51+
[here](https://github.com/yaahc/blog.rust-lang.org/blob/master/posts/inside-rust/2021-05-15-What-the-error-handling-project-group-is-working-towards.md#duplicate-information-issue).*
4352

4453
<br>
4554

4655
### Details
4756

48-
- A `Display` impl is generated for your type if you provide doc comment
49-
messages on the struct or each variant of your enum, as shown above in the
50-
example.
51-
52-
The messages support a shorthand for interpolating fields from the error.
53-
57+
- A `fmt::Display` impl is generated for your enum if you provide
58+
a docstring comment on each variant as shown above in the example. The
59+
`Display` derive macro supports a shorthand for interpolating fields from
60+
the error:
5461
- `/// {var}``write!("{}", self.var)`
5562
- `/// {0}``write!("{}", self.0)`
5663
- `/// {var:?}``write!("{:?}", self.var)`
5764
- `/// {0:?}``write!("{:?}", self.0)`
65+
- This also works with structs and [generic types][crate::Display#generic-type-parameters]:
66+
```rust
67+
/// oh no, an error: {0}
68+
#[derive(Display)]
69+
pub struct Error<E>(pub E);
70+
71+
let error: Error<&str> = Error("muahaha i am an error");
72+
assert!("oh no, an error: muahaha i am an error" == &format!("{}", error));
73+
```
5874

5975
- Two optional attributes can be added to your types next to the derive:
6076

@@ -77,10 +93,10 @@ pub enum DataStoreError {
7793
### FAQ
7894

7995
1. **Is this crate `no_std` compatible?**
80-
* Yes! This crate implements the `core::fmt::Display` trait not the `std::fmt::Display` trait so it should work in `std` and `no_std` environments. Just add `default-features = false`.
96+
* Yes! This crate implements the [`core::fmt::Display`] trait, not the [`std::fmt::Display`] trait, so it should work in `std` and `no_std` environments. Just add `default-features = false`.
8197

8298
2. **Does this crate work with `Path` and `PathBuf` via the `Display` trait?**
83-
* Yuuup. This crate uses @dtolnay's [autoref specialization technique](https://github.com/dtolnay/case-studies/blob/master/autoref-specialization/README.md) to add a special trait for types to get the display impl, it then specializes for `Path` and `PathBuf` and when either of these types are found it calls `self.display()` to get a `std::path::Display<'_>` type which can be used with the Display format specifier!
99+
* Yuuup. This crate uses @dtolnay's [autoref specialization technique](https://github.com/dtolnay/case-studies/blob/master/autoref-specialization/README.md) to add a special trait for types to get the display impl. It then specializes for `Path` and `PathBuf`, and when either of these types are found, it calls `self.display()` to get a `std::path::Display<'_>` type which can be used with the `Display` format specifier!
84100

85101

86102
#### License

0 commit comments

Comments
 (0)