1use std::fmt;
2
3#[derive(Debug)]
5#[non_exhaustive]
6pub enum Error {
7 LinkIsNotImage,
9
10 Generic(String),
12}
13
14impl fmt::Display for Error {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 Self::LinkIsNotImage => write!(f, "The provided link does not lead to an image file, or the Content-Type is unspecified."),
18 Self::Generic(s) => write!(f, "{s}"),
19 }
20 }
21}
22
23macro_rules! impl_from {
24 ($from:ty) => {
25 impl From<$from> for Error {
26 fn from(e: $from) -> Self {
27 Self::Generic(e.to_string())
28 }
29 }
30 };
31}
32
33impl_from!(reqwest::Error);
34impl_from!(reqwest::header::ToStrError);
35impl_from!(serde_json::Error);
36impl_from!(std::num::ParseFloatError);
37impl_from!(Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>);