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
use image::error::ImageError;
use std::error::Error;
use std::fmt::{Display, Formatter, Result};
use std::io;
#[derive(Debug)]
pub enum PConvertError {
ArgumentError(String),
UnsupportedImageTypeError,
IOError(io::Error),
ImageLibError(ImageError),
}
impl Display for PConvertError {
fn fmt(&self, formatter: &mut Formatter) -> Result {
match &*self {
PConvertError::UnsupportedImageTypeError => write!(
formatter,
"UnsupportedImageTypeError: images should be PNGs encoded as RGBA8"
),
PConvertError::ImageLibError(err) => err.fmt(formatter),
PConvertError::IOError(err) => err.fmt(formatter),
PConvertError::ArgumentError(msg) => write!(formatter, "{}", msg),
}
}
}
impl Error for PConvertError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
PConvertError::UnsupportedImageTypeError => None,
PConvertError::ArgumentError(_) => None,
PConvertError::ImageLibError(ref err) => Some(err),
PConvertError::IOError(ref err) => Some(err),
}
}
}
impl From<io::Error> for PConvertError {
fn from(err: io::Error) -> PConvertError {
PConvertError::IOError(err)
}
}
impl From<ImageError> for PConvertError {
fn from(err: ImageError) -> PConvertError {
PConvertError::ImageLibError(err)
}
}