devela/media/color/
error.rs

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
// devela::media::color::error
//
//!
//

#[doc = crate::TAG_RESULT!()]
/// A color-related result.
pub type ColorResult<T> = crate::Result<T, ColorError>;

#[doc = crate::TAG_ERROR_COMPOSITE!()]
/// A color-related error.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)] // Hash
pub enum ColorError {
    /// The requested chromatic functionality is not implemented.
    ///
    /// This is the default implementation of every `Color` method.
    NotImplemented,

    /// The requested chromatic functionality is not supported by this color type.
    NotSupported,
}

#[allow(dead_code)]
impl ColorError {
    pub(crate) const fn ni<T>() -> ColorResult<T> {
        Err(ColorError::NotImplemented)
    }
    pub(crate) const fn ns<T>() -> ColorResult<T> {
        Err(ColorError::NotSupported)
    }
}

mod core_impls {
    use crate::{ColorError, Display, FmtResult, Formatter};

    impl crate::Error for ColorError {}
    impl crate::ExtError for ColorError {
        type Kind = ();
        fn error_eq(&self, other: &Self) -> bool {
            self == other
        }
        fn error_kind(&self) -> Self::Kind {}
    }

    impl Display for ColorError {
        fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
            use ColorError as E;
            match self {
                E::NotImplemented => write!(f, "Not implemented."),
                E::NotSupported => write!(f, "Not supported."),
            }
        }
    }
}