use std::error::Error;
use std::fmt;
use std::io;
#[derive(Debug)]
pub enum TiffError {
FormatError(String),
UnsupportedError(String),
IoError(io::Error),
}
impl fmt::Display for TiffError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
TiffError::FormatError(ref e) => write!(fmt, "Format error: {}", e),
TiffError::UnsupportedError(ref f) => write!(fmt, "The Decoder does not support the \
image format `{}`", f),
TiffError::IoError(ref e) => e.fmt(fmt),
}
}
}
impl Error for TiffError {
fn description (&self) -> &str {
match *self {
TiffError::FormatError(..) => "Format error",
TiffError::UnsupportedError(..) => "Unsupported error",
TiffError::IoError(..) => "IO error",
}
}
fn cause (&self) -> Option<&Error> {
match *self {
TiffError::IoError(ref e) => Some(e),
_ => None
}
}
}
impl From<io::Error> for TiffError {
fn from(err: io::Error) -> TiffError {
TiffError::IoError(err)
}
}
pub type TiffResult<T> = Result<T, TiffError>;