use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum DecodeError {
FfiError(&'static str),
ReadHeader,
NullInString,
TooManyComponents(usize),
UnspecifiedColorSpace,
UnknownColorSpace,
}
impl From<::std::ffi::NulError> for DecodeError {
fn from(_: ::std::ffi::NulError) -> Self {
DecodeError::NullInString
}
}
impl Error for DecodeError {
fn description(&self) -> &str {
match *self {
DecodeError::FfiError(e) => e,
DecodeError::ReadHeader => "reading the header failed",
DecodeError::NullInString => "there was a null byte in the string",
DecodeError::TooManyComponents(_) => {
"there were too many components in the supplied file."
}
DecodeError::UnspecifiedColorSpace => "Color space was not specified.",
DecodeError::UnknownColorSpace => "Color space is unknown.",
}
}
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}