diff --git a/src/chunk.rs b/src/chunk.rs index 7a220b1..0b78b5e 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -1,7 +1,11 @@ use futures::{Async, Stream}; -use std::io::Cursor; -use std::mem; -use std::sync::Arc; +use std::{ + error::Error, + fmt::{Display, Formatter, Result as FmtResult}, + io::Cursor, + mem, + sync::Arc +}; use ebml::EbmlEventSource; use webm::*; @@ -92,6 +96,20 @@ pub enum ChunkingError { OtherError(E) } +impl Display for ChunkingError { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "Chunking error: {}", self.description()) + } +} +impl Error for ChunkingError { + fn description(&self) -> &str { + match self { + &ChunkingError::IoError(ref err) => err.description(), + &ChunkingError::OtherError(ref err) => err.description() + } + } +} + pub struct WebmChunker { source: S, state: ChunkerState diff --git a/src/ebml.rs b/src/ebml.rs index a9fc150..cfb9876 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -15,6 +15,21 @@ pub enum EbmlError { UnknownElementLength, CorruptPayload, } +impl Display for EbmlError { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", self.description()) + } +} +impl ErrorTrait for EbmlError { + fn description(&self) -> &str { + match self { + &EbmlError::CorruptVarint => "EBML Varint could not be parsed", + &EbmlError::UnknownElementId => "EBML element ID was \"unknown\"", + &EbmlError::UnknownElementLength => "EBML element length was \"unknown\" for an element not allowing that", + &EbmlError::CorruptPayload => "EBML element payload could not be parsed", + } + } +} #[derive(Debug, PartialEq)] pub enum WriteError { diff --git a/src/stream_parser.rs b/src/stream_parser.rs index a2c99a5..645ccf3 100644 --- a/src/stream_parser.rs +++ b/src/stream_parser.rs @@ -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 { EbmlError(EbmlError), OtherError(E) } +impl Display for ParsingError { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "Parsing error: {}", self.description()) + } +} +impl Error for ParsingError { + fn description(&self) -> &str { + match self { + &ParsingError::EbmlError(ref err) => err.description(), + &ParsingError::OtherError(ref err) => err.description() + } + } +} pub struct EbmlStreamingParser { stream: S,