icon_loader/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3
4pub use crate::theme_name_provider::error::Error as ProviderError;
5
6/// Type alias for `std::result::Result<T, Error>`
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Error type returned by this crate.
10#[derive(Debug)]
11pub enum Error {
12    /// No theme with the given name could be found.
13    ThemeNotFound {
14        /// The given theme name.
15        theme_name: String,
16    },
17
18    /// Error updating the default theme name.
19    ThemeNameProvider {
20        /// The source for the error.
21        source: ProviderError,
22    },
23}
24
25impl Error {
26    pub(crate) fn theme_not_found(theme_name: impl Into<String>) -> Self {
27        Error::ThemeNotFound {
28            theme_name: theme_name.into(),
29        }
30    }
31}
32
33impl StdError for Error {
34    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35        match self {
36            Error::ThemeNameProvider { source } => Some(source),
37            _ => None,
38        }
39    }
40}
41
42impl fmt::Display for Error {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Error::ThemeNotFound { theme_name } => {
46                write!(f, "Theme with name {} not found", theme_name)
47            }
48            Error::ThemeNameProvider { source } => {
49                write!(f, "Error updating default theme name: {}", source)
50            }
51        }
52    }
53}
54
55impl From<ProviderError> for Error {
56    fn from(source: ProviderError) -> Self {
57        Error::ThemeNameProvider { source }
58    }
59}