1use image::error::ImageError;
4use std::error::Error;
5use std::fmt::{Display, Formatter, Result};
6use std::io;
7
8#[derive(Debug)]
10pub enum PConvertError {
11 ArgumentError(String),
12 UnsupportedImageTypeError,
13 IOError(io::Error),
14 ImageLibError(ImageError),
15}
16
17impl Display for PConvertError {
18 fn fmt(&self, formatter: &mut Formatter) -> Result {
19 match self {
20 PConvertError::UnsupportedImageTypeError => write!(
21 formatter,
22 "UnsupportedImageTypeError: images should be PNGs encoded as RGBA8"
23 ),
24 PConvertError::ImageLibError(err) => err.fmt(formatter),
25 PConvertError::IOError(err) => err.fmt(formatter),
26 PConvertError::ArgumentError(msg) => write!(formatter, "{}", msg),
27 }
28 }
29}
30
31impl Error for PConvertError {
32 fn source(&self) -> Option<&(dyn Error + 'static)> {
33 match *self {
34 PConvertError::UnsupportedImageTypeError => None,
35 PConvertError::ArgumentError(_) => None,
36 PConvertError::ImageLibError(ref err) => Some(err),
37 PConvertError::IOError(ref err) => Some(err),
38 }
39 }
40}
41
42impl From<io::Error> for PConvertError {
43 fn from(err: io::Error) -> PConvertError {
44 PConvertError::IOError(err)
45 }
46}
47
48impl From<ImageError> for PConvertError {
49 fn from(err: ImageError) -> PConvertError {
50 PConvertError::ImageLibError(err)
51 }
52}