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