Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum DataStoreError {
#[error("data store disconnected")]
#[error("data store disconnected: {0}")]
Disconnect(#[from] io::Error),
#[error("the data for key `{0}` is not available")]
Redaction(String),
Expand Down Expand Up @@ -93,6 +93,10 @@ pub enum DataStoreError {
source error (and possibly a backtrace — see below). Usually `#[from]`
fields are unnamed, but `#[from]` is allowed on a named field too.

To include the source's `Display` output in your error message, use `{0}`
(or `{var}` for a named field) in the `#[error("...")]` format string, as in
the `Disconnect` example above.

```rust
#[derive(Error, Debug)]
pub enum MyError {
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//!
//! #[derive(Error, Debug)]
//! pub enum DataStoreError {
//! #[error("data store disconnected")]
//! #[error("data store disconnected: {0}")]
//! Disconnect(#[from] io::Error),
//! #[error("the data for key `{0}` is not available")]
//! Redaction(String),
Expand Down Expand Up @@ -104,6 +104,10 @@
//! `#[from]` fields are unnamed, but `#[from]` is allowed on a named field
//! too.
//!
//! To include the source's [`Display`] output in your error message, use
//! `{0}` (or `{var}` for a named field) in the `#[error("...")]` format
//! string, as in the `Disconnect` example above.
//!
//! ```rust
//! # use core::fmt::{self, Display};
//! # use std::io;
Expand Down
Loading