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
44
45
46
47
48
49
50
51
52
53
54
type StdError = dyn std::error::Error + 'static;
#[derive(Debug)]
pub struct Chain<'a> {
next: Option<&'a StdError>,
}
impl<'a> Chain<'a> {
pub(crate) fn new(next: Option<&'a StdError>) -> Self {
Self { next }
}
}
impl<'a> Iterator for Chain<'a> {
type Item = &'a StdError;
fn next(&mut self) -> Option<Self::Item> {
let next = self.next.take()?;
self.next = next.source();
Some(next)
}
}
#[cfg(test)]
mod test {
use super::*;
use static_assertions::*;
#[test]
fn chain() {
assert_impl_all!(Chain: std::fmt::Debug);
}
}