pbcodec/
error.rs

1use std;
2use trackable;
3use trackable::error::TrackableError;
4use trackable::error::ErrorKind as TrackableErrorKind;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum ErrorKind {
8    Unsupported,
9    Invalid,
10    UnexpectedEos,
11    Other,
12}
13impl TrackableErrorKind for ErrorKind {}
14
15#[derive(Debug)]
16pub struct Error<T> {
17    pub stream: T,
18    pub error: TrackableError<ErrorKind>,
19}
20impl<T> std::fmt::Display for Error<T> {
21    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
22        self.error.fmt(f)
23    }
24}
25impl<T: std::fmt::Debug> std::error::Error for Error<T> {
26    fn description(&self) -> &str {
27        self.error.description()
28    }
29    fn cause(&self) -> Option<&std::error::Error> {
30        self.error.cause()
31    }
32}
33impl<T> trackable::Trackable for Error<T> {
34    type Event = trackable::Location;
35    fn history(&self) -> Option<&trackable::error::History> {
36        self.error.history()
37    }
38    fn history_mut(&mut self) -> Option<&mut trackable::error::History> {
39        self.error.history_mut()
40    }
41}
42impl<T> From<Error<T>> for TrackableError<ErrorKind> {
43    fn from(f: Error<T>) -> Self {
44        f.error
45    }
46}