use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum PngLoadingError {
UnsupportedBitDepth(png::BitDepth),
PngError(png::DecodingError),
}
impl fmt::Display for PngLoadingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use PngLoadingError::*;
match self {
UnsupportedBitDepth(bit_depth) => {
write!(f, "unsupported bit depth (not 8 or 16): {:?}", bit_depth)
}
PngError(err) => err.fmt(f),
}
}
}
impl Error for PngLoadingError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
PngLoadingError::PngError(err) => Some(err),
_ => None,
}
}
}
impl From<png::DecodingError> for PngLoadingError {
fn from(other: png::DecodingError) -> PngLoadingError {
PngLoadingError::PngError(other)
}
}