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

// NOTE: IoError doesn't implement Clone, PartialEq, Hash, etc.
#[cfg(feature = "sys")]
use crate::IoError;
#[cfg(feature = "layout")]
use crate::LayoutError;

#[doc = crate::TAG_RESULT!()]
/// A user-interface result.
pub type UiResult<T> = core::result::Result<T, UiError>;

/// A user-interface error.
#[non_exhaustive]
#[derive(Debug)]
pub enum UiError {
    /// The requested numerical functionality is not implemented.
    ///
    /// This is the default implementation of every numeric trait method.
    NotImplemented,

    /// The requested functionality is not supported by this number type.
    NotSupported,

    /// Layout-related error.
    #[cfg(feature = "layout")]
    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "layout")))]
    Layout(LayoutError),

    /// An io error.
    #[cfg(feature = "sys")]
    Io(IoError),
}

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

impl crate::Error for UiError {}

mod core_impls {
    use super::*;
    use crate::impl_trait;
    #[cfg(feature = "layout")]
    use crate::LayoutError;

    impl_trait! { fmt::Display for UiError |self, f| {
        use UiError as E;
        match self {
            #[cfg(feature = "layout")]
            E::Layout(e) => write!(f, "{e:?}"),

            E::NotImplemented => write!(f, "Not implemented."),
            E::NotSupported => write!(f, "Not supported."),
            #[cfg(feature = "sys")]
            E::Io(e) => write!(f, "{e:?}"),
        }
    }}

    #[cfg(feature = "layout")]
    impl From<LayoutError> for UiError {
        fn from(e: LayoutError) -> Self {
            UiError::Layout(e)
        }
    }

    #[cfg(feature = "sys")]
    impl From<IoError> for UiError {
        fn from(err: IoError) -> Self {
            UiError::Io(err)
        }
    }
}