snafu/
error_chain.rs

1/// An iterator over an Error and its sources.
2///
3/// If you want to omit the initial error and only process its sources, use `skip(1)`.
4///
5/// Can be created via [`ErrorCompat::iter_chain`][crate::ErrorCompat::iter_chain].
6#[derive(Debug, Clone)]
7pub struct ChainCompat<'a> {
8    inner: Option<&'a dyn crate::Error>,
9}
10
11impl<'a> ChainCompat<'a> {
12    /// Creates a new error chain iterator.
13    pub fn new(error: &'a dyn crate::Error) -> Self {
14        ChainCompat { inner: Some(error) }
15    }
16}
17
18impl<'a> Iterator for ChainCompat<'a> {
19    type Item = &'a dyn crate::Error;
20
21    fn next(&mut self) -> Option<Self::Item> {
22        match self.inner {
23            None => None,
24            Some(e) => {
25                self.inner = e.source();
26                Some(e)
27            }
28        }
29    }
30}