devela/ui/
error.rs
1#[cfg(feature = "sys")]
8use crate::IoError;
9#[cfg(feature = "layout")]
10use crate::LayoutError;
11
12#[doc = crate::TAG_RESULT!()]
13pub type UiResult<T> = core::result::Result<T, UiError>;
15
16#[non_exhaustive]
18#[derive(Debug)]
19pub enum UiError {
20 NotImplemented,
24
25 NotSupported,
27
28 #[cfg(feature = "layout")]
30 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "layout")))]
31 Layout(LayoutError),
32
33 #[cfg(feature = "sys")]
35 Io(IoError),
36}
37
38#[allow(dead_code)]
39impl UiError {
40 pub(crate) const fn ni<T>() -> UiResult<T> {
41 Err(UiError::NotImplemented)
42 }
43 pub(crate) const fn ns<T>() -> UiResult<T> {
44 Err(UiError::NotSupported)
45 }
46}
47
48impl crate::Error for UiError {}
49
50mod core_impls {
51 use super::*;
52 use crate::impl_trait;
53 #[cfg(feature = "layout")]
54 use crate::LayoutError;
55
56 impl_trait! { fmt::Display for UiError |self, f| {
57 use UiError as E;
58 match self {
59 #[cfg(feature = "layout")]
60 E::Layout(e) => write!(f, "{e:?}"),
61
62 E::NotImplemented => write!(f, "Not implemented."),
63 E::NotSupported => write!(f, "Not supported."),
64 #[cfg(feature = "sys")]
65 E::Io(e) => write!(f, "{e:?}"),
66 }
67 }}
68
69 #[cfg(feature = "layout")]
70 impl From<LayoutError> for UiError {
71 fn from(e: LayoutError) -> Self {
72 UiError::Layout(e)
73 }
74 }
75
76 #[cfg(feature = "sys")]
77 impl From<IoError> for UiError {
78 fn from(err: IoError) -> Self {
79 UiError::Io(err)
80 }
81 }
82}