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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
InvalidInput,
NotSupported,
Unimplemented,
MissingFeature(&'static str),
StackUnbalance,
BackendError(Box<dyn std::error::Error>),
MissingFont,
FontLoadingFailed,
#[cfg(feature = "samples")]
InvalidSampleArgs,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::InvalidInput => write!(f, "Invalid input"),
Error::NotSupported => write!(f, "Not supported on the current backend"),
Error::StackUnbalance => write!(f, "Stack unbalanced"),
Error::MissingFont => write!(f, "A font could not be found"),
Error::FontLoadingFailed => write!(f, "A font could not be loaded"),
Error::Unimplemented => write!(
f,
"This functionality is not yet implemented for this backend"
),
Error::MissingFeature(feature) => write!(f, "Missing feature '{feature}'"),
Error::BackendError(e) => {
write!(f, "Backend error: ")?;
e.fmt(f)
}
#[cfg(feature = "samples")]
Error::InvalidSampleArgs => write!(f, "Must pass either --all or a number"),
}
}
}
impl std::error::Error for Error {}
impl From<Box<dyn std::error::Error>> for Error {
fn from(e: Box<dyn std::error::Error>) -> Error {
Error::BackendError(e)
}
}