use std::{error::Error, fmt::Display};
use thiserror::Error;
pub type UIResult<T> = Result<T, UIError>;
#[derive(Debug)]
pub struct UIError {
pub(crate) kind: UIErrorKind,
}
impl UIError {
#[must_use]
pub fn kind(&self) -> &UIErrorKind {
&self.kind
}
}
impl Display for UIError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.kind.fmt(f)
}
}
impl Error for UIError {}
#[derive(Debug, PartialEq, Eq, Error)]
pub enum UIErrorKind {
#[error("failed to allocate a platform-dependent resource: {resource}")]
AllocationFailed { resource: &'static str },
#[error("cannot inspect system window")]
CannotInspectSystemWindow,
#[error("failed to convert between platform-specific types: {description}")]
ConversionError{ description: &'static str },
#[error("feature `{feature:?}` disabled")]
FeatureDisabled { feature: UIFeature },
#[error("platform issue: {issue}")]
PlatformIssue { issue: &'static str },
#[error("the current platform is not supported")]
PlatformNotSupported,
#[error("the process has no windows")]
ProcessHasNoWindows,
}
impl From<UIErrorKind> for UIError {
fn from(value: UIErrorKind) -> Self {
Self {
kind: value,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UIFeature {
Accessibility,
}