Skip to main content

lcsa_core/
capabilities.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum SignalUnsupportedReason {
7    PlatformNotSupported,
8    BackendNotImplemented,
9    RequiresX11Display,
10    RequiresAccessibilityPermission,
11    RuntimeDependencyMissing,
12}
13
14impl SignalUnsupportedReason {
15    pub fn as_str(self) -> &'static str {
16        match self {
17            SignalUnsupportedReason::PlatformNotSupported => "platform_not_supported",
18            SignalUnsupportedReason::BackendNotImplemented => "backend_not_implemented",
19            SignalUnsupportedReason::RequiresX11Display => "requires_x11_display",
20            SignalUnsupportedReason::RequiresAccessibilityPermission => {
21                "requires_accessibility_permission"
22            }
23            SignalUnsupportedReason::RuntimeDependencyMissing => "runtime_dependency_missing",
24        }
25    }
26}
27
28impl fmt::Display for SignalUnsupportedReason {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        f.write_str(self.as_str())
31    }
32}
33
34#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
35#[serde(tag = "status", content = "reason", rename_all = "snake_case")]
36pub enum SignalSupport {
37    Supported,
38    Unsupported(SignalUnsupportedReason),
39}
40
41impl SignalSupport {
42    pub fn as_str(self) -> String {
43        match self {
44            SignalSupport::Supported => "supported".to_string(),
45            SignalSupport::Unsupported(reason) => format!("unsupported:{}", reason.as_str()),
46        }
47    }
48}
49
50impl fmt::Display for SignalSupport {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        match self {
53            SignalSupport::Supported => f.write_str("supported"),
54            SignalSupport::Unsupported(reason) => write!(f, "unsupported:{reason}"),
55        }
56    }
57}
58
59impl SignalSupport {
60    pub fn is_supported(self) -> bool {
61        matches!(self, SignalSupport::Supported)
62    }
63}