feat(error): implement Error::source when available

Closes #1768
This commit is contained in:
Steven Fackler
2019-02-27 13:18:02 -08:00
committed by Sean McArthur
parent 0bf30ccc68
commit 4cf22dfa21
3 changed files with 22 additions and 0 deletions

View File

@@ -323,6 +323,7 @@ impl StdError for Error {
}
}
#[cfg(not(error_source))]
fn cause(&self) -> Option<&StdError> {
self
.inner
@@ -330,6 +331,15 @@ impl StdError for Error {
.as_ref()
.map(|cause| &**cause as &StdError)
}
#[cfg(error_source)]
fn source(&self) -> Option<&(StdError + 'static)> {
self
.inner
.cause
.as_ref()
.map(|cause| &**cause as &(StdError + 'static))
}
}
#[doc(hidden)]