Skip to main content

visionkit/
support.rs

1use serde::{Deserialize, Serialize};
2
3use crate::error::VisionKitError;
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7/// Represents VisionKit availability information for an API area.
8pub struct AreaSupportInfo {
9    /// Stores the VisionKit area value.
10    pub area: String,
11    /// Stores the VisionKit current platform value.
12    pub current_platform: String,
13    /// Indicates whether VisionKit reports this area as available on the current platform.
14    pub available_on_current_platform: bool,
15    /// Stores the VisionKit availability value.
16    pub availability: String,
17    /// Stores the VisionKit reason value.
18    pub reason: Option<String>,
19    /// Stores the VisionKit members value.
20    pub members: Vec<String>,
21    #[serde(default)]
22    /// Stores the VisionKit notes value.
23    pub notes: Vec<String>,
24}
25
26impl AreaSupportInfo {
27    #[must_use]
28    /// Builds the VisionKit availability error for this unsupported area.
29    pub fn unavailable_error(&self) -> VisionKitError {
30        VisionKitError::UnavailableOnThisPlatform(self.reason.clone().unwrap_or_else(|| {
31            let area = &self.area;
32            let current_platform = &self.current_platform;
33            format!("{area} is unavailable on {current_platform}")
34        }))
35    }
36}