devela/media/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// devela::media::error
//
//!
//

#[cfg(feature = "audio")]
use crate::AudioError;
#[cfg(feature = "color")]
use crate::ColorError;
#[cfg(feature = "draw")]
use crate::DrawError;
#[cfg(feature = "font")]
use crate::FontError;
#[cfg(feature = "image")]
use crate::ImageError;

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

#[doc = crate::TAG_ERROR_COMPOSITE!()]
/// A media-related error.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MediaError {
    ///
    #[cfg(feature = "audio")]
    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "audio")))]
    Audio(AudioError),
    ///
    #[cfg(feature = "color")]
    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "color")))]
    Color(ColorError),
    ///
    #[cfg(feature = "draw")]
    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "draw")))]
    Draw(DrawError),
    ///
    #[cfg(feature = "font")]
    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "font")))]
    Font(FontError),
    ///
    #[cfg(feature = "image")]
    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "font")))]
    Image(ImageError),
}

mod core_impls {
    #[cfg(feature = "audio")]
    use crate::AudioError;
    #[cfg(feature = "color")]
    use crate::ColorError;
    #[cfg(feature = "draw")]
    use crate::DrawError;
    #[cfg(feature = "font")]
    use crate::FontError;
    #[cfg(feature = "image")]
    use crate::ImageError;
    use crate::{Display, FmtResult, Formatter, MediaError};

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

    impl Display for MediaError {
        fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
            match self {
                #[cfg(feature = "audio")]
                MediaError::Audio(e) => write!(f, "{e:?}"),
                #[cfg(feature = "color")]
                MediaError::Color(e) => write!(f, "{e:?}"),
                #[cfg(feature = "draw")]
                MediaError::Draw(e) => write!(f, "{e:?}"),
                #[cfg(feature = "font")]
                MediaError::Font(e) => write!(f, "{e:?}"),
                #[cfg(feature = "image")]
                MediaError::Image(e) => write!(f, "{e:?}"),
            }
        }
    }
    #[cfg(feature = "audio")]
    impl From<AudioError> for MediaError {
        fn from(e: AudioError) -> Self {
            Self::Audio(e)
        }
    }
    #[cfg(feature = "color")]
    impl From<ColorError> for MediaError {
        fn from(e: ColorError) -> Self {
            Self::Color(e)
        }
    }
    #[cfg(feature = "draw")]
    impl From<DrawError> for MediaError {
        fn from(e: DrawError) -> Self {
            Self::Draw(e)
        }
    }
    #[cfg(feature = "font")]
    impl From<FontError> for MediaError {
        fn from(e: FontError) -> Self {
            Self::Font(e)
        }
    }
    #[cfg(feature = "image")]
    impl From<ImageError> for MediaError {
        fn from(e: ImageError) -> Self {
            Self::Image(e)
        }
    }
}