use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Support {
Supported,
Unsupported,
Unknown,
}
impl Support {
pub fn is_supported(self) -> bool {
matches!(self, Support::Supported)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlatformCapabilities {
pub native_service_manager: Support,
pub filesystem_events: Support,
pub secure_secret_storage: Support,
pub process_containment: Support,
pub native_notifications: Support,
pub accelerator_telemetry: Support,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_supported_is_true_only_for_the_supported_variant() {
assert!(Support::Supported.is_supported());
assert!(!Support::Unsupported.is_supported());
assert!(!Support::Unknown.is_supported());
}
#[test]
fn unknown_serializes_as_its_own_distinct_value_not_false() {
let value = serde_json::to_value(Support::Unknown).unwrap();
assert_eq!(value, serde_json::json!("unknown"));
assert_ne!(value, serde_json::json!(false));
}
#[test]
fn capabilities_round_trip_through_json() {
let capabilities = PlatformCapabilities {
native_service_manager: Support::Supported,
filesystem_events: Support::Unknown,
secure_secret_storage: Support::Unsupported,
process_containment: Support::Unknown,
native_notifications: Support::Supported,
accelerator_telemetry: Support::Unknown,
};
let text = serde_json::to_string(&capabilities).unwrap();
let round_tripped: PlatformCapabilities = serde_json::from_str(&text).unwrap();
assert_eq!(round_tripped.filesystem_events, Support::Unknown);
assert_eq!(round_tripped.secure_secret_storage, Support::Unsupported);
}
}