Create unified error type
This commit is contained in:
parent
15ebdb6b8c
commit
a9932ee6a1
2 changed files with 56 additions and 0 deletions
55
src/error.rs
Normal file
55
src/error.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use std::{
|
||||
error::Error,
|
||||
fmt::{
|
||||
Display,
|
||||
Formatter,
|
||||
Result as FmtResult
|
||||
},
|
||||
io::Error as IoError
|
||||
};
|
||||
|
||||
use ebml::EbmlError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum WebmetroError {
|
||||
EbmlError(EbmlError),
|
||||
IoError(IoError),
|
||||
Unknown(Box<Error>)
|
||||
}
|
||||
|
||||
impl Display for WebmetroError {
|
||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||
match self {
|
||||
&WebmetroError::EbmlError(ref err) => err.fmt(f),
|
||||
&WebmetroError::IoError(ref err) => err.fmt(f),
|
||||
&WebmetroError::Unknown(ref err) => err.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Error for WebmetroError {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
&WebmetroError::EbmlError(ref err) => err.description(),
|
||||
&WebmetroError::IoError(ref err) => err.description(),
|
||||
&WebmetroError::Unknown(ref err) => err.description(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EbmlError> for WebmetroError {
|
||||
fn from(err: EbmlError) -> WebmetroError {
|
||||
WebmetroError::EbmlError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IoError> for WebmetroError {
|
||||
fn from(err: IoError) -> WebmetroError {
|
||||
WebmetroError::IoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<Error>> for WebmetroError {
|
||||
fn from(err: Box<Error>) -> WebmetroError {
|
||||
WebmetroError::Unknown(err)
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ extern crate futures;
|
|||
extern crate odds;
|
||||
|
||||
pub mod ebml;
|
||||
pub mod error;
|
||||
pub mod iterator;
|
||||
pub mod slice;
|
||||
pub mod stream_parser;
|
||||
|
|
Loading…
Reference in a new issue