ready-cache: Properly expose error source (#467)

The `ready_cache::error::Failed` type does not actually expose its inner
error type via `Error::source`. This change fixes this and improves
debug formatting.

This change adds a new constraint, ensuring that keys impl Debug in
order for the `error::Failed` type to impl Debug/Error.
This commit is contained in:
Oliver Gould 2020-08-31 07:21:04 -07:00 committed by GitHub
parent ab7518ef13
commit ad348d8ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -6,9 +6,12 @@ pub struct Failed<K>(pub K, pub crate::BoxError);
// === Failed ===
impl<K> std::fmt::Debug for Failed<K> {
impl<K: std::fmt::Debug> std::fmt::Debug for Failed<K> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.1, f)
f.debug_tuple("Failed")
.field(&self.0)
.field(&self.1)
.finish()
}
}
@ -18,8 +21,8 @@ impl<K> std::fmt::Display for Failed<K> {
}
}
impl<K> std::error::Error for Failed<K> {
impl<K: std::fmt::Debug> std::error::Error for Failed<K> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.1.source()
Some(&*self.1)
}
}