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

use std::borrow::Cow;
use failure::Fail;



pub type ImageResult<T> = Result<T, ImageError>;
pub type ImageResultU = Result<(), ImageError>;



#[derive(Fail, Debug)]
pub enum ImageError {
    #[fail(display = "Corrupt image: {}", 0)]
    CorruptImage(Cow<'static, str>),
    #[fail(display = "Invalid signature")]
    InvalidSignature,
    #[fail(display = "IO Error: {}", 0)]
    Io(std::io::Error),
    #[fail(display = "Unsupported format")]
    Unsupported,
}


macro_rules! define_error {
    ($source:ty, $kind:ident) => {
        impl From<$source> for ImageError {
            fn from(error: $source) -> ImageError {
                ImageError::$kind(error)
            }
        }
    }
}

define_error!(std::io::Error, Io);