provide a default impl for the Display trait

This commit is contained in:
Jane Lusby 2020-04-07 13:02:58 -07:00 committed by Jane Lusby
parent ab76683def
commit 7a9d480c99
3 changed files with 20 additions and 26 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "eyre" name = "eyre"
version = "0.3.5" # remember to update html_root_url version = "0.3.6" # remember to update html_root_url
authors = ["David Tolnay <dtolnay@gmail.com>", "Jane Lusby <jlusby42@gmail.com>"] authors = ["David Tolnay <dtolnay@gmail.com>", "Jane Lusby <jlusby42@gmail.com>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View File

@ -58,8 +58,8 @@ eyre = "0.3"
## Customization ## Customization
In order to insert your own custom context type you must first implement the In order to insert your own custom context type you must first implement the
`eyre::EyreContext` trait for said type, which has three required methods and `eyre::EyreContext` trait for said type, which has two required methods and
two optional methods. three optional methods.
### Required Methods ### Required Methods
@ -80,8 +80,8 @@ fn default(error: &(dyn StdError + 'static)) -> Self {
``` ```
* `fn debug(&self, error: &(dyn Error + 'static), f: &mut fmt::Formatter<'_>) * `fn debug(&self, error: &(dyn Error + 'static), f: &mut fmt::Formatter<'_>)
-> fmt Result` and it's companion fn `display`. - For formatting the entire -> fmt Result` and optionally `display` - For formatting the entire error
error chain and the user provided context. chain and the user provided context.
When overriding the context it no longer makes sense for `eyre::ErrReport` to When overriding the context it no longer makes sense for `eyre::ErrReport` to
provide the `Display` and `Debug` implementations for the user, becase we provide the `Display` and `Debug` implementations for the user, becase we

View File

@ -50,8 +50,8 @@
//! ## Customization //! ## Customization
//! //!
//! In order to insert your own custom context type you must first implement the //! In order to insert your own custom context type you must first implement the
//! `eyre::EyreContext` trait for said type, which has three required methods and //! `eyre::EyreContext` trait for said type, which has two required methods and
//! two optional methods. //! three optional methods.
//! //!
//! ### Required Methods //! ### Required Methods
//! //!
@ -72,7 +72,7 @@
//! ``` //! ```
//! //!
//! * `fn debug(&self, error: &(dyn Error + 'static), f: &mut fmt::Formatter<'_>) //! * `fn debug(&self, error: &(dyn Error + 'static), f: &mut fmt::Formatter<'_>)
//! -> fmt Result` and it's companion fn `display`. - For formatting the entire //! -> fmt Result` and optionally `display`. - For formatting the entire
//! error chain and the user provided context. //! error chain and the user provided context.
//! //!
//! When overriding the context it no longer makes sense for `eyre::ErrReport` to //! When overriding the context it no longer makes sense for `eyre::ErrReport` to
@ -314,7 +314,7 @@
//! [`anyhow`]: https://github.com/dtolnay/anyhow //! [`anyhow`]: https://github.com/dtolnay/anyhow
//! [`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing-error/struct.SpanTrace.html //! [`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing-error/struct.SpanTrace.html
#![doc(html_root_url = "https://docs.rs/eyre/0.3.5")] #![doc(html_root_url = "https://docs.rs/eyre/0.3.6")]
#![cfg_attr(backtrace, feature(backtrace))] #![cfg_attr(backtrace, feature(backtrace))]
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![allow( #![allow(
@ -485,7 +485,17 @@ pub trait EyreContext: Sized + Send + Sync + 'static {
&self, &self,
error: &(dyn StdError + 'static), error: &(dyn StdError + 'static),
f: &mut core::fmt::Formatter<'_>, f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result; ) -> core::fmt::Result {
write!(f, "{}", error)?;
if f.alternate() {
for cause in crate::chain::Chain::new(error).skip(1) {
write!(f, ": {}", cause)?;
}
}
Ok(())
}
fn debug( fn debug(
&self, &self,
@ -514,22 +524,6 @@ impl EyreContext for DefaultContext {
} }
} }
fn display(
&self,
error: &(dyn StdError + 'static),
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
write!(f, "{}", error)?;
if f.alternate() {
for cause in crate::chain::Chain::new(error).skip(1) {
write!(f, ": {}", cause)?;
}
}
Ok(())
}
fn debug( fn debug(
&self, &self,
error: &(dyn StdError + 'static), error: &(dyn StdError + 'static),