use std::fmt;
use std::io;
use std::error;
use std::string::FromUtf8Error;
#[derive(Debug)]
pub enum Error {
Utf8(FromUtf8Error),
Internal(String),
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Internal(format!("{:?}", err))
}
}
impl From<FromUtf8Error> for Error {
fn from(err: FromUtf8Error) -> Error {
Error::Utf8(err)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Utf8(ref e) => write!(f, "Utf8 decode Error: {:?}", e),
Error::Internal(ref st) => write!(f, "Internal Error: {:?}", st),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::Utf8(ref e) => e.description(),
Error::Internal(ref st) => st,
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
Error::Utf8(ref e) => Some(e),
Error::Internal(_) => None,
}
}
}