add find_chain_or_cause()

This commit is contained in:
Harald Hoyer 2019-01-26 10:44:25 +01:00
parent e7d4afb86c
commit 694cb4f273

View file

@ -290,6 +290,16 @@ impl<T: 'static + Display + Debug> ChainError<T> {
.next() .next()
} }
// FIXME: naming
fn find_chain_or_cause<U: Error + 'static>(&self) -> Option<&U> {
self.iter()
.filter_map(|e| {
e.downcast_ref::<ChainError<U>>().map(|e| e.kind())
.or_else(|| e.downcast_ref::<U>())
})
.next()
}
/** return a reference to T of `ChainError<T>` /** return a reference to T of `ChainError<T>`
# Examples # Examples