impl Error for error types

This commit is contained in:
Tangent 2018-04-12 01:59:28 -04:00
parent e61244bce3
commit bac34e94c5
3 changed files with 54 additions and 3 deletions

View file

@ -1,3 +1,8 @@
use std::{
error::Error,
fmt::{Display, Formatter, Result as FmtResult}
};
use bytes::BytesMut;
use bytes::BufMut;
use futures::Async;
@ -12,6 +17,19 @@ pub enum ParsingError<E> {
EbmlError(EbmlError),
OtherError(E)
}
impl<E: Display + Error> Display for ParsingError<E> {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "Parsing error: {}", self.description())
}
}
impl<E: Error> Error for ParsingError<E> {
fn description(&self) -> &str {
match self {
&ParsingError::EbmlError(ref err) => err.description(),
&ParsingError::OtherError(ref err) => err.description()
}
}
}
pub struct EbmlStreamingParser<S> {
stream: S,