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
use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
LinkIsNotImage,
Generic(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::LinkIsNotImage => write!(f, "The provided link does not lead to an image file, or the Content-Type is unspecified."),
Self::Generic(s) => write!(f, "{s}"),
}
}
}
macro_rules! impl_from {
($from:ty) => {
impl From<$from> for Error {
fn from(e: $from) -> Self {
Self::Generic(e.to_string())
}
}
};
}
impl_from!(reqwest::Error);
impl_from!(reqwest::header::ToStrError);
impl_from!(serde_json::Error);
impl_from!(std::num::ParseFloatError);
impl_from!(Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>);