Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section about not including sources in Display impl #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/interoperability.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,27 @@ be lowercase without trailing punctuation, and typically concise.
[`Error::description()`] should not be implemented. It has been deprecated and users should
always use `Display` instead of `description()` to print the error.

If an error type returns an underlying source error from [`Error::source()`], it does **not**
include that source error in its own `Display` representation as well. This avoids duplicated
information when an error is printed along with all its sources:

```rust
use std::fmt;

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Good errors never duplicate information like this:
write!(f, "failed to parse: {}", self.source),

// Instead they just describe themselves:
write!(f, "failed to parse"),
}
}
```

[`Error::description()`]: https://doc.rust-lang.org/std/error/trait.Error.html#tymethod.description
[`Error::source()`]: https://doc.rust-lang.org/std/error/trait.Error.html#method.source


### Examples from the standard library

Expand Down