1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! A module for image errors

pub(crate) use self::messages::*;

mod messages;

use std::io;

/// Type alias for `Result<T, ImgProcError>`
pub type ImgProcResult<T> = Result<T, ImgProcError>;

/// Type alias for `Result<T, ImgIoError>`
pub type ImgIoResult<T> = Result<T, ImgIoError>;

/// An enum for image processing errors
#[derive(Debug)]
pub enum ImgProcError {
    InvalidArgError(String),
    NumericError(String),
    RulinalgError(rulinalg::error::Error),
}

impl From<rulinalg::error::Error> for ImgProcError {
    fn from(err: rulinalg::error::Error) -> Self {
        ImgProcError::RulinalgError(err)
    }
}

/// An enum for image i/o errors
#[derive(Debug)]
pub enum ImgIoError {
    UnsupportedFileFormatError(String),
    UnsupportedColorTypeError(String),
    IoError(io::Error),
    ImageReaderError(image::error::ImageError),
    ImageWriteError(String),
    OtherError(String),
}

impl From<io::Error> for ImgIoError {
    fn from(err: io::Error) -> Self {
        ImgIoError::IoError(err)
    }
}

impl From<image::error::ImageError> for ImgIoError {
    fn from(err: image::error::ImageError) -> Self {
        ImgIoError::ImageReaderError(err)
    }
}

impl From<String> for ImgIoError {
    fn from(err: String) -> Self {
        ImgIoError::OtherError(err)
    }
}