Skip to content

Commit

Permalink
Bump to 0.2.4 (#43)
Browse files Browse the repository at this point in the history
* Bump to 0.2.4

* Update readme
  • Loading branch information
Manishearth authored May 3, 2023
1 parent a0a7083 commit f0b62a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

# [0.2.4] - 2022-05-02

## Added
- Updated `syn` dependency to 2.0
- Support for empty enums
- Implicitly require fmt::Display on all type parameters unless overridden

## Changed
- Bumped MSRV to 1.56

# [0.2.3] - 2021-07-16
## Added
- Added `#[displaydoc("..")]` attribute for overriding a doc comment
Expand All @@ -32,7 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
lines are needed.

<!-- next-url -->
[Unreleased]: https://github.com/yaahc/displaydoc/compare/v0.2.3...HEAD
[Unreleased]: https://github.com/yaahc/displaydoc/compare/v0.2.4...HEAD
[0.2.4]: https://github.com/yaahc/displaydoc/compare/v0.2.3...v0.2.4
[0.2.3]: https://github.com/yaahc/displaydoc/compare/v0.2.2...v0.2.3
[0.2.2]: https://github.com/yaahc/displaydoc/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/yaahc/displaydoc/compare/v0.2.0...v0.2.1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "displaydoc"
version = "0.2.3"
version = "0.2.4"
authors = ["Jane Lusby <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ displaydoc = "0.2"

### Example

*Demonstration alongside the [`Error`][std::error::Error] derive macro from [`thiserror`](https://docs.rs/thiserror/1.0.25/thiserror/index.html),
to propagate source locations from [`io::Error`][std::io::Error] with the `#[source]` attribute:*
```rust
use std::io;
use displaydoc::Display;
Expand All @@ -39,22 +41,36 @@ pub enum DataStoreError {
/// unknown data store error
Unknown,
}

let error = DataStoreError::Redaction("CLASSIFIED CONTENT".to_string());
assert!("the data for key `CLASSIFIED CONTENT` is not available" == &format!("{}", error));
```
*Note that although [`io::Error`][std::io::Error] implements `Display`, we do not add it to the
generated message for `DataStoreError::Disconnect`, since it is already made available via
`#[source]`. See further context on avoiding duplication in error reports at the rust blog
[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).*

<br>

### Details

- A `Display` impl is generated for your type if you provide doc comment
messages on the struct or each variant of your enum, as shown above in the
example.

The messages support a shorthand for interpolating fields from the error.

- A `fmt::Display` impl is generated for your enum if you provide
a docstring comment on each variant as shown above in the example. The
`Display` derive macro supports a shorthand for interpolating fields from
the error:
- `/// {var}``write!("{}", self.var)`
- `/// {0}``write!("{}", self.0)`
- `/// {var:?}``write!("{:?}", self.var)`
- `/// {0:?}``write!("{:?}", self.0)`
- This also works with structs and [generic types][crate::Display#generic-type-parameters]:
```rust
/// oh no, an error: {0}
#[derive(Display)]
pub struct Error<E>(pub E);

let error: Error<&str> = Error("muahaha i am an error");
assert!("oh no, an error: muahaha i am an error" == &format!("{}", error));
```

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

Expand All @@ -77,10 +93,10 @@ pub enum DataStoreError {
### FAQ

1. **Is this crate `no_std` compatible?**
* 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`.
* 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`.

2. **Does this crate work with `Path` and `PathBuf` via the `Display` trait?**
* 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!
* 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!


#### License
Expand Down

0 comments on commit f0b62a5

Please sign in to comment.