devela/code/result/error/
all_error.rs
1use crate::impl_error;
17
18impl_error![individual: pub struct FailedErrorConversion;
19 DOC_FAILED_CONVERSION = "A failed conversion between two error types.",
20 self+f => write!(f, "Failed to convert between error types"),
21];
22impl_error![individual: pub struct NotImplemented;
23 DOC_NOT_IMPLEMENTED = "The requested functionality is not implemented.",
24 self+f => write!(f, "The requested functionality is not implemented."),
25];
26impl_error![individual: pub struct NotSupported;
27 DOC_NOT_SUPPORTED = "The requested functionality is not supported by this type.",
28 self+f => write!(f, "The requested functionality is not supported by this type."),
29];
30
31impl_error! { composite: fmt(f)
34 pub enum NotAvailable {
39 DOC_NOT_IMPLEMENTED: NotImplemented => NotImplemented,
40 DOC_NOT_SUPPORTED: NotSupported => NotSupported,
41 }
42}
43
44#[cfg(feature = "error")]
45pub use full_composite::*;
46#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "error")))]
47#[cfg(feature = "error")]
48mod full_composite {
49 use super::super::reexports::crate_errors::*;
50 #[doc = crate::TAG_RESULT!()]
53 pub type AllResult<T> = crate::Result<T, AllError>;
55
56 #[doc = crate::TAG_ERROR_COMPOSITE!()]
57 #[derive(Debug)]
64 pub enum AllError {
65 #[cfg(data··)]
67 #[cfg_attr(feature = "nightly_doc", doc(cfg(data··)))]
68 Data(DataError),
69
70 #[cfg(media··)]
72 #[cfg_attr(feature = "nightly_doc", doc(cfg(media··)))]
73 Media(MediaError),
74
75 Num(NumError),
77
78 #[cfg(feature = "io")]
81 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "io")))]
82 Io(IoError),
83
84 #[cfg(text··)]
86 #[cfg_attr(feature = "nightly_doc", doc(cfg(text··)))]
87 Text(TextError),
88
89 #[cfg(feature = "time")]
92 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "time")))]
93 Time(TimeError),
94
95 Other(&'static str),
97 }
98
99 #[doc = crate::TAG_ERROR_COMPOSITE!()]
100 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
104 pub enum AllErrorKind {
105 #[cfg(data··)]
107 #[cfg_attr(feature = "nightly_doc", doc(cfg(data··)))]
108 Data(()), #[cfg(media··)]
112 #[cfg_attr(feature = "nightly_doc", doc(cfg(media··)))]
113 Media(()), Num(()), #[cfg(feature = "io")]
120 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "io")))]
121 Io(IoErrorKind),
122
123 #[cfg(feature = "time")]
125 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "time")))]
126 Time(()), #[cfg(text··)]
130 #[cfg_attr(feature = "nightly_doc", doc(cfg(text··)))]
131 Text(()), Other,
135 }
139
140 mod core_impls {
141 use super::*;
142 use crate::impl_trait;
143
144 impl crate::Error for AllError {}
145 impl crate::ExtError for AllError {
146 type Kind = AllErrorKind;
147
148 fn error_eq(&self, other: &Self) -> bool {
149 use AllError as E;
150 match (self, other) {
151 #[cfg(data··)]
152 (E::Data(e1), E::Data(e2)) => e1.error_eq(e2),
153 #[cfg(media··)]
154 (E::Media(e1), E::Media(e2)) => e1.error_eq(e2),
155 (E::Num(e1), E::Num(e2)) => e1.error_eq(e2),
156 #[cfg(feature = "io")]
157 (E::Io(e1), E::Io(e2)) => e1.error_eq(e2),
158 #[cfg(feature = "time")]
159 (E::Time(e1), E::Time(e2)) => e1.error_eq(e2),
160 #[cfg(text··)]
161 (E::Text(e1), E::Text(e2)) => e1.error_eq(e2),
162 (E::Other(s1), E::Other(s2)) => s1 == s2,
163
164 _ => false, }
166 }
167 fn error_kind(&self) -> Self::Kind {
168 use {AllError as E, AllErrorKind as K};
169 #[expect(clippy::unit_arg, reason = "WIP () placeholder")]
170 match self {
171 #[cfg(data··)]
172 E::Data(e) => K::Data(e.error_kind()),
173 #[cfg(media··)]
174 E::Media(e) => K::Media(e.error_kind()),
175 E::Num(e) => K::Num(e.error_kind()),
176 #[cfg(feature = "io")]
177 E::Io(e) => K::Io(e.error_kind()),
178 #[cfg(feature = "time")]
179 E::Time(e) => K::Time(e.error_kind()),
180 #[cfg(text··)]
181 E::Text(e) => K::Text(e.error_kind()),
182 E::Other(_s) => K::Other,
183 }
184 }
185 }
186
187 impl_trait! { fmt::Display for AllError |self, f| {
188 use AllError as E;
189 match self {
190 #[cfg(data··)]
191 E::Data(e) => write!(f, "{e:?}"),
192 #[cfg(media··)]
193 E::Media(e) => write!(f, "{e:?}"),
194 E::Num(e) => write!(f, "{e:?}"),
195 #[cfg(feature = "io")]
196 E::Io(e) => write!(f, "{e:?}"),
197 #[cfg(feature = "time")]
198 E::Time(e) => write!(f, "{e:?}"),
199 #[cfg(text··)]
200 E::Text(e) => write!(f, "{e:?}"),
201 E::Other(s) => write!(f, "{s}"),
202 }
203 }}
204 }
205}