devela/media/
error.rs
1#[cfg(feature = "audio")]
7use crate::AudioError;
8#[cfg(feature = "color")]
9use crate::ColorError;
10#[cfg(feature = "draw")]
11use crate::DrawError;
12#[cfg(feature = "font")]
13use crate::FontError;
14#[cfg(feature = "image")]
15use crate::ImageError;
16
17#[doc = crate::TAG_RESULT!()]
18pub type MediaResult<T> = crate::Result<T, MediaError>;
20
21#[doc = crate::TAG_ERROR_COMPOSITE!()]
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24pub enum MediaError {
25 #[cfg(feature = "audio")]
27 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "audio")))]
28 Audio(AudioError),
29 #[cfg(feature = "color")]
31 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "color")))]
32 Color(ColorError),
33 #[cfg(feature = "draw")]
35 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "draw")))]
36 Draw(DrawError),
37 #[cfg(feature = "font")]
39 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "font")))]
40 Font(FontError),
41 #[cfg(feature = "image")]
43 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "font")))]
44 Image(ImageError),
45}
46
47mod core_impls {
48 #[cfg(feature = "audio")]
49 use crate::AudioError;
50 #[cfg(feature = "color")]
51 use crate::ColorError;
52 #[cfg(feature = "draw")]
53 use crate::DrawError;
54 #[cfg(feature = "font")]
55 use crate::FontError;
56 #[cfg(feature = "image")]
57 use crate::ImageError;
58 use crate::{Display, FmtResult, Formatter, MediaError};
59
60 impl crate::Error for MediaError {}
61 impl crate::ExtError for MediaError {
62 type Kind = ();
63 fn error_eq(&self, other: &Self) -> bool {
64 self == other
65 }
66 fn error_kind(&self) -> Self::Kind {}
67 }
68
69 impl Display for MediaError {
70 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
71 match self {
72 #[cfg(feature = "audio")]
73 MediaError::Audio(e) => write!(f, "{e:?}"),
74 #[cfg(feature = "color")]
75 MediaError::Color(e) => write!(f, "{e:?}"),
76 #[cfg(feature = "draw")]
77 MediaError::Draw(e) => write!(f, "{e:?}"),
78 #[cfg(feature = "font")]
79 MediaError::Font(e) => write!(f, "{e:?}"),
80 #[cfg(feature = "image")]
81 MediaError::Image(e) => write!(f, "{e:?}"),
82 }
83 }
84 }
85 #[cfg(feature = "audio")]
86 impl From<AudioError> for MediaError {
87 fn from(e: AudioError) -> Self {
88 Self::Audio(e)
89 }
90 }
91 #[cfg(feature = "color")]
92 impl From<ColorError> for MediaError {
93 fn from(e: ColorError) -> Self {
94 Self::Color(e)
95 }
96 }
97 #[cfg(feature = "draw")]
98 impl From<DrawError> for MediaError {
99 fn from(e: DrawError) -> Self {
100 Self::Draw(e)
101 }
102 }
103 #[cfg(feature = "font")]
104 impl From<FontError> for MediaError {
105 fn from(e: FontError) -> Self {
106 Self::Font(e)
107 }
108 }
109 #[cfg(feature = "image")]
110 impl From<ImageError> for MediaError {
111 fn from(e: ImageError) -> Self {
112 Self::Image(e)
113 }
114 }
115}