From 79b9476ddb69ae1459241fdfd43cc400a313b6da Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 17 Jan 2025 15:35:56 -0800 Subject: [PATCH] new: Add unstable setting. --- crates/pdk-api/src/api/mod.rs | 5 ++++- crates/pdk-api/src/shapes.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/pdk-api/src/api/mod.rs b/crates/pdk-api/src/api/mod.rs index 67133e47c..6a0194366 100644 --- a/crates/pdk-api/src/api/mod.rs +++ b/crates/pdk-api/src/api/mod.rs @@ -1,6 +1,6 @@ mod build_source; -use crate::shapes::StringOrVec; +use crate::shapes::*; use rustc_hash::FxHashMap; use std::path::PathBuf; use version_spec::{CalVer, SemVer, SpecError, UnresolvedVersionSpec, VersionSpec}; @@ -109,6 +109,9 @@ api_struct!( /// Type of the tool. #[serde(rename = "type")] pub type_of: PluginType, + + /// Whether this plugin is unstable or not. + pub unstable: Switch, } ); diff --git a/crates/pdk-api/src/shapes.rs b/crates/pdk-api/src/shapes.rs index 8b1bdbd60..88ab36cdc 100644 --- a/crates/pdk-api/src/shapes.rs +++ b/crates/pdk-api/src/shapes.rs @@ -17,3 +17,27 @@ impl StringOrVec { } } } + +api_enum!( + /// Either a boolean representing on or off, or a string representing on with a message. + #[serde(untagged)] + pub enum Switch { + Toggle(bool), + Message(String), + } +); + +impl Default for Switch { + fn default() -> Self { + Self::Toggle(false) + } +} + +impl Switch { + pub fn is_enabled(&self) -> bool { + match self { + Self::Toggle(value) => *value, + Self::Message(_) => true, + } + } +}