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
use std::fmt;
use std::fmt::{Debug, Formatter, Result as FmtResult};

#[derive(Debug)]
pub enum Error {
    #[cfg(feature = "sync")]
    ErrorSpawningThread(std::io::Error),
    TimedOut,
    Disconnected,
}

impl std::error::Error for Error {}
impl fmt::Display for Error {
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        write!(
            f,
            "TimeoutIteratorError:: {}",
            match self {
                Self::TimedOut =>
                    "Timed out waiting on the underlying iterator for the next item".to_owned(),
                Self::Disconnected => "Underlying iterator closed/disconnected".to_owned(),

                #[cfg(feature = "sync")]
                Self::ErrorSpawningThread(e) => format!(
                    "Error when spawing a thread for sinking events. Inner io::Error: {}",
                    e
                ),
            }
        )
    }
}

#[cfg(feature = "sync")]
impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Self {
        Self::ErrorSpawningThread(err)
    }
}