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
55
56
57
58
59
60
use std;
use trackable;
use trackable::error::TrackableError;
use trackable::error::ErrorKind as TrackableErrorKind;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ErrorKind {
    Unsupported,
    Invalid,
    UnexpectedEos,
    Other,
}
impl TrackableErrorKind for ErrorKind {}

#[derive(Debug)]
pub struct Error<T> {
    pub stream: T,
    pub error: TrackableError<ErrorKind>,
}
impl<T> std::fmt::Display for Error<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        self.error.fmt(f)
    }
}
impl<T: std::fmt::Debug> std::error::Error for Error<T> {
    fn description(&self) -> &str {
        self.error.description()
    }
    fn cause(&self) -> Option<&std::error::Error> {
        self.error.cause()
    }
}
impl<T> trackable::Trackable for Error<T> {
    type Event = trackable::error::Event;
    fn enable_tracking(mut self) -> Self
    where
        Self: Sized,
    {
        self.error = self.error.enable_tracking();
        self
    }
    fn disable_tracking(mut self) -> Self
    where
        Self: Sized,
    {
        self.error = self.error.disable_tracking();
        self
    }
    fn history(&self) -> Option<&trackable::History<Self::Event>> {
        self.error.history()
    }
    fn history_mut(&mut self) -> Option<&mut trackable::History<Self::Event>> {
        self.error.history_mut()
    }
}
impl<T> From<Error<T>> for TrackableError<ErrorKind> {
    fn from(f: Error<T>) -> Self {
        f.error
    }
}