impl Error for error types

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

View File

@ -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<E> {
OtherError(E)
}
impl<E: Display + Error> Display for ChunkingError<E> {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "Chunking error: {}", self.description())
}
}
impl<E: Error> Error for ChunkingError<E> {
fn description(&self) -> &str {
match self {
&ChunkingError::IoError(ref err) => err.description(),
&ChunkingError::OtherError(ref err) => err.description()
}
}
}
pub struct WebmChunker<S> {
source: S,
state: ChunkerState

View File

@ -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 {

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,