use std::fmt;
use std::error;
#[derive(Debug)]
pub enum ErrorKind {
ImageNotFound,
CoreFoundation,
Opencv(opencv::Error),
}
#[derive(Debug)]
pub struct Error {
pub kind: ErrorKind,
pub message: String,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
ErrorKind::ImageNotFound => write!(f, "Image not found: {}", self.message),
ErrorKind::CoreFoundation => write!(f, "Core Foundation: {}", self.message),
ErrorKind::Opencv(ref e) => write!(f, "OpenCV Error: {}", e),
}
}
}
impl error::Error for Error { }
impl From<opencv::Error> for Error {
fn from(err: opencv::Error) -> Error {
Error {
message: err.to_string(),
kind: ErrorKind::Opencv(err),
}
}
}