1use std::{error::Error, fmt::Display};
5
6use thiserror::Error;
7
8pub type UIResult<T> = Result<T, UIError>;
9
10#[derive(Debug)]
11pub struct UIError {
12 pub(crate) kind: UIErrorKind,
13}
14
15impl UIError {
16 #[must_use]
17 pub fn kind(&self) -> &UIErrorKind {
18 &self.kind
19 }
20}
21
22impl Display for UIError {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 self.kind.fmt(f)
25 }
26}
27
28impl Error for UIError {}
29
30#[derive(Debug, PartialEq, Eq, Error)]
31pub enum UIErrorKind {
32 #[error("failed to allocate a platform-dependent resource: {resource}")]
33 AllocationFailed { resource: &'static str },
34
35 #[error("cannot inspect system window")]
36 CannotInspectSystemWindow,
37
38 #[error("failed to convert between platform-specific types: {description}")]
39 ConversionError{ description: &'static str },
40
41 #[error("feature `{feature:?}` disabled")]
42 FeatureDisabled { feature: UIFeature },
43
44 #[error("platform issue: {issue}")]
45 PlatformIssue { issue: &'static str },
46
47 #[error("the current platform is not supported")]
48 PlatformNotSupported,
49
50 #[error("the process has no windows")]
51 ProcessHasNoWindows,
52}
53
54impl From<UIErrorKind> for UIError {
55 fn from(value: UIErrorKind) -> Self {
56 Self {
57 kind: value,
58 }
59 }
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63pub enum UIFeature {
64 Accessibility,
65}