impl Error for error types
This commit is contained in:
parent
e61244bce3
commit
bac34e94c5
3 changed files with 54 additions and 3 deletions
24
src/chunk.rs
24
src/chunk.rs
|
@ -1,7 +1,11 @@
|
||||||
use futures::{Async, Stream};
|
use futures::{Async, Stream};
|
||||||
use std::io::Cursor;
|
use std::{
|
||||||
use std::mem;
|
error::Error,
|
||||||
use std::sync::Arc;
|
fmt::{Display, Formatter, Result as FmtResult},
|
||||||
|
io::Cursor,
|
||||||
|
mem,
|
||||||
|
sync::Arc
|
||||||
|
};
|
||||||
use ebml::EbmlEventSource;
|
use ebml::EbmlEventSource;
|
||||||
use webm::*;
|
use webm::*;
|
||||||
|
|
||||||
|
@ -92,6 +96,20 @@ pub enum ChunkingError<E> {
|
||||||
OtherError(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> {
|
pub struct WebmChunker<S> {
|
||||||
source: S,
|
source: S,
|
||||||
state: ChunkerState
|
state: ChunkerState
|
||||||
|
|
15
src/ebml.rs
15
src/ebml.rs
|
@ -15,6 +15,21 @@ pub enum EbmlError {
|
||||||
UnknownElementLength,
|
UnknownElementLength,
|
||||||
CorruptPayload,
|
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)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum WriteError {
|
pub enum WriteError {
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
use std::{
|
||||||
|
error::Error,
|
||||||
|
fmt::{Display, Formatter, Result as FmtResult}
|
||||||
|
};
|
||||||
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use futures::Async;
|
use futures::Async;
|
||||||
|
@ -12,6 +17,19 @@ pub enum ParsingError<E> {
|
||||||
EbmlError(EbmlError),
|
EbmlError(EbmlError),
|
||||||
OtherError(E)
|
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> {
|
pub struct EbmlStreamingParser<S> {
|
||||||
stream: S,
|
stream: S,
|
||||||
|
|
Loading…
Reference in a new issue