Refactor a bit

Rename the Image* types to Tiff*
Extract the "common" types to the top level.
This commit is contained in:
R.Chavignat committed 2018-03-13 00:07:06 +01:00
1 parent 7c46be100d
commit 0c623bc3a3
5 files changed
+110 -129

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
use std::error::Error;
use std::fmt;
use std::io;
/// An enumeration of Tiff errors
#[derive(Debug)]
pub enum TiffError {
/// The Image is not formatted properly
FormatError(String),
/// The Decoder does not support this image format
UnsupportedError(String),
/// An I/O Error occurred while decoding the image
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)
}
}
/// Result of an image decoding/encoding process
pub type TiffResult<T> = Result<T, TiffError>;