mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
add find_chain_or_cause()
This commit is contained in:
parent
e7d4afb86c
commit
694cb4f273
10
src/lib.rs
10
src/lib.rs
|
@ -290,6 +290,16 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
.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>`
|
||||
|
||||
# Examples
|
||||
|
|
Loading…
Reference in a new issue