You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.4 KiB
78 lines
1.4 KiB
use super::*;
|
|
use std::{
|
|
error,
|
|
fmt,
|
|
io,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error
|
|
{
|
|
/// Image format could not be determined.
|
|
UnknownFormat,
|
|
/// Image is not valid
|
|
InvalidFormat,
|
|
/// Image decode failedb
|
|
DecodeError,
|
|
|
|
// Internals
|
|
/// IO error
|
|
IO(io::Error),
|
|
/// Failed to format text
|
|
Formatter(fmt::Error),
|
|
/// Something bad
|
|
Unknown,
|
|
}
|
|
|
|
impl error::Error for Error
|
|
{
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)>
|
|
{
|
|
Some(match &self {
|
|
Self::IO(io) => io,
|
|
Self::Formatter(fmt) => fmt,
|
|
_ => return None,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Error
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
write!(f, "loli module: ")?;
|
|
match self {
|
|
Self::UnknownFormat => write!(f, "could not determine image format"),
|
|
Self::InvalidFormat => write!(f, "image is not valid"),
|
|
Self::DecodeError => write!(f, "image decode failed"),
|
|
Self::IO(io) => write!(f, "io: {}", io),
|
|
Self::Formatter(fmt) => write!(f, "formatting: {}", fmt),
|
|
_ => write!(f, "unknown error"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<io::Error> for Error
|
|
{
|
|
fn from(er: io::Error) -> Self
|
|
{
|
|
Self::IO(er)
|
|
}
|
|
}
|
|
|
|
impl From<fmt::Error> for Error
|
|
{
|
|
fn from(er: fmt::Error) -> Self
|
|
{
|
|
Self::Formatter(er)
|
|
}
|
|
}
|
|
|
|
impl From<base64::DecodeError> for Error
|
|
{
|
|
fn from(_er: base64::DecodeError) -> Self
|
|
{
|
|
Self::DecodeError
|
|
}
|
|
}
|