proto_pdk_api/
shapes.rs

1use warpgate_api::api_enum;
2
3api_enum!(
4    /// Either a string, or a list of strings.
5    #[serde(untagged)]
6    pub enum StringOrVec {
7        String(String),
8        Vec(Vec<String>),
9    }
10);
11
12impl StringOrVec {
13    pub fn as_string(&self) -> String {
14        match self {
15            Self::String(value) => value.to_owned(),
16            Self::Vec(value) => value.to_vec().join(" "),
17        }
18    }
19}
20
21api_enum!(
22    /// Either a boolean representing on or off, or a string representing on with a message.
23    #[serde(untagged)]
24    pub enum Switch {
25        Toggle(bool),
26        Message(String),
27    }
28);
29
30impl Default for Switch {
31    fn default() -> Self {
32        Self::Toggle(false)
33    }
34}
35
36impl Switch {
37    pub fn is_enabled(&self) -> bool {
38        match self {
39            Self::Toggle(value) => *value,
40            Self::Message(_) => true,
41        }
42    }
43}