1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate erroneous_derive;
pub use erroneous_derive::Error;
use std::error::Error as StdError;
pub trait Error: StdError + Send + Sync + 'static {
fn iter<'a>(&'a self) -> Iter<'a>;
}
pub struct Iter<'a> {
error: Option<&'a (dyn StdError + 'static)>,
}
impl<'a> Iterator for Iter<'a> {
type Item = &'a (dyn StdError + 'static);
fn next(&mut self) -> Option<Self::Item> {
if let Some(error) = self.error {
self.error = error.source();
Some(error)
} else {
None
}
}
}
impl<T: StdError + Send + Sync + 'static> Error for T {
fn iter<'a>(&'a self) -> Iter<'a> {
Iter { error: Some(self) }
}
}