use std::error;
use std::num::ParseIntError;
use curl::Error;
#[derive(Debug)]
pub enum YarError {
URLError(&'static str),
TimeError(ParseIntError),
CURLError(Error),
CallErr(String),
}
impl From<ParseIntError> for YarError{
fn from(err:ParseIntError) -> YarError {
YarError::TimeError(err)
}
}
impl From<Error> for YarError{
fn from(err: Error) -> YarError {
YarError::CURLError(err)
}
}
impl error::Error for YarError{
fn description(&self) -> &str {
match *self {
YarError::TimeError(ref err) => err.description(),
YarError::CURLError(ref err) => err.description(),
YarError::URLError(description)=> description,
YarError::CallErr(ref description) => description.as_str(),
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
YarError::URLError(_) => None,
YarError::TimeError(ref err)=> Some(err as &error::Error),
YarError::CURLError(ref err)=> Some(err as &error::Error),
YarError::CallErr(_)=> None,
}
}
}
use std::fmt;
impl fmt::Display for YarError{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
YarError::TimeError(ref err) => fmt::Display::fmt(err, f),
YarError::CURLError(ref err) => fmt::Display::fmt(err, f),
YarError::URLError(desc) => f.write_str(desc),
YarError::CallErr(ref desc) => f.write_str(desc.as_str()),
}
}
}