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

@@ -38,6 +38,9 @@ tokio-threadpool = { version = "0.1.3", optional = true }
tokio-timer = { version = "0.2", optional = true }
want = "0.0.6"
[build-dependencies]
rustc_version = "0.2"
[dev-dependencies]
futures-timer = "0.1"
num_cpus = "1.0"

9
build.rs Normal file
View File

@@ -0,0 +1,9 @@
extern crate rustc_version;
use rustc_version::{version, Version};
fn main() {
if version().unwrap() >= Version::parse("1.30.0").unwrap() {
println!("cargo:rustc-cfg=error_source");
}
}

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)]