Pull in thiserror library for tests

This commit is contained in:
David Tolnay 2019-10-09 11:14:00 -07:00
parent d4bc68cf65
commit a37dea2133
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 11 additions and 6 deletions

View File

@ -12,3 +12,6 @@ readme = "README.md"
[features]
default = ["std"]
std = []
[dev-dependencies]
thiserror = "1.0"

View File

@ -86,14 +86,16 @@ anyhow = "1.0"
[thiserror]: https://github.com/dtolnay/thiserror
```rust
use thiserror::Error;
#[derive(Error, Debug)]
pub enum FormatError {
#[error(display = "invalid header (expected {:?}, got {:?})", expected, found)]
#[error("invalid header (expected {expected:?}, got {found:?})")]
InvalidHeader {
expected: String,
found: String,
},
#[error(display = "missing attribute: {}", _0)]
#[error("missing attribute: {0}")]
MissingAttribute(String),
}
```

View File

@ -132,18 +132,18 @@
//! [thiserror]: https://github.com/dtolnay/thiserror
//!
//! ```
//! # const IGNORE: &str = stringify! {
//! use thiserror::Error;
//!
//! #[derive(Error, Debug)]
//! pub enum FormatError {
//! #[error(display = "invalid header (expected {:?}, got {:?})", expected, found)]
//! #[error("invalid header (expected {expected:?}, got {found:?})")]
//! InvalidHeader {
//! expected: String,
//! found: String,
//! },
//! #[error(display = "missing attribute: {}", _0)]
//! #[error("missing attribute: {0}")]
//! MissingAttribute(String),
//! }
//! # };
//! ```
//!
//! - One-off error messages can be constructed using the `anyhow!` macro, which