Skip to main content

nominal_api/conjure/objects/scout/compute/api/
resource_search_query.rs

1use conjure_object::serde::{ser, de};
2use conjure_object::serde::ser::SerializeMap as SerializeMap_;
3use conjure_object::private::{UnionField_, UnionTypeField_};
4use std::fmt;
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum ResourceSearchQuery {
7    Properties(super::super::super::rids::api::PropertiesFilter),
8    Labels(super::super::super::rids::api::LabelsFilter),
9    Workspace(Box<super::StringConstant>),
10    And(Vec<super::ResourceSearchQuery>),
11    Or(Vec<super::ResourceSearchQuery>),
12    Not(Box<super::ResourceSearchQuery>),
13    /// An unknown variant.
14    Unknown(Unknown),
15}
16impl ser::Serialize for ResourceSearchQuery {
17    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
18    where
19        S: ser::Serializer,
20    {
21        let mut map = s.serialize_map(Some(2))?;
22        match self {
23            ResourceSearchQuery::Properties(value) => {
24                map.serialize_entry(&"type", &"properties")?;
25                map.serialize_entry(&"properties", value)?;
26            }
27            ResourceSearchQuery::Labels(value) => {
28                map.serialize_entry(&"type", &"labels")?;
29                map.serialize_entry(&"labels", value)?;
30            }
31            ResourceSearchQuery::Workspace(value) => {
32                map.serialize_entry(&"type", &"workspace")?;
33                map.serialize_entry(&"workspace", value)?;
34            }
35            ResourceSearchQuery::And(value) => {
36                map.serialize_entry(&"type", &"and")?;
37                map.serialize_entry(&"and", value)?;
38            }
39            ResourceSearchQuery::Or(value) => {
40                map.serialize_entry(&"type", &"or")?;
41                map.serialize_entry(&"or", value)?;
42            }
43            ResourceSearchQuery::Not(value) => {
44                map.serialize_entry(&"type", &"not")?;
45                map.serialize_entry(&"not", value)?;
46            }
47            ResourceSearchQuery::Unknown(value) => {
48                map.serialize_entry(&"type", &value.type_)?;
49                map.serialize_entry(&value.type_, &value.value)?;
50            }
51        }
52        map.end()
53    }
54}
55impl<'de> de::Deserialize<'de> for ResourceSearchQuery {
56    fn deserialize<D>(d: D) -> Result<ResourceSearchQuery, D::Error>
57    where
58        D: de::Deserializer<'de>,
59    {
60        d.deserialize_map(Visitor_)
61    }
62}
63struct Visitor_;
64impl<'de> de::Visitor<'de> for Visitor_ {
65    type Value = ResourceSearchQuery;
66    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
67        fmt.write_str("union ResourceSearchQuery")
68    }
69    fn visit_map<A>(self, mut map: A) -> Result<ResourceSearchQuery, A::Error>
70    where
71        A: de::MapAccess<'de>,
72    {
73        let v = match map.next_key::<UnionField_<Variant_>>()? {
74            Some(UnionField_::Type) => {
75                let variant = map.next_value()?;
76                let key = map.next_key()?;
77                match (variant, key) {
78                    (Variant_::Properties, Some(Variant_::Properties)) => {
79                        let value = map.next_value()?;
80                        ResourceSearchQuery::Properties(value)
81                    }
82                    (Variant_::Labels, Some(Variant_::Labels)) => {
83                        let value = map.next_value()?;
84                        ResourceSearchQuery::Labels(value)
85                    }
86                    (Variant_::Workspace, Some(Variant_::Workspace)) => {
87                        let value = map.next_value()?;
88                        ResourceSearchQuery::Workspace(value)
89                    }
90                    (Variant_::And, Some(Variant_::And)) => {
91                        let value = map.next_value()?;
92                        ResourceSearchQuery::And(value)
93                    }
94                    (Variant_::Or, Some(Variant_::Or)) => {
95                        let value = map.next_value()?;
96                        ResourceSearchQuery::Or(value)
97                    }
98                    (Variant_::Not, Some(Variant_::Not)) => {
99                        let value = map.next_value()?;
100                        ResourceSearchQuery::Not(value)
101                    }
102                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
103                        if type_ == b {
104                            let value = map.next_value()?;
105                            ResourceSearchQuery::Unknown(Unknown { type_, value })
106                        } else {
107                            return Err(
108                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
109                            )
110                        }
111                    }
112                    (variant, Some(key)) => {
113                        return Err(
114                            de::Error::invalid_value(
115                                de::Unexpected::Str(key.as_str()),
116                                &variant.as_str(),
117                            ),
118                        );
119                    }
120                    (variant, None) => {
121                        return Err(de::Error::missing_field(variant.as_str()));
122                    }
123                }
124            }
125            Some(UnionField_::Value(variant)) => {
126                let value = match &variant {
127                    Variant_::Properties => {
128                        let value = map.next_value()?;
129                        ResourceSearchQuery::Properties(value)
130                    }
131                    Variant_::Labels => {
132                        let value = map.next_value()?;
133                        ResourceSearchQuery::Labels(value)
134                    }
135                    Variant_::Workspace => {
136                        let value = map.next_value()?;
137                        ResourceSearchQuery::Workspace(value)
138                    }
139                    Variant_::And => {
140                        let value = map.next_value()?;
141                        ResourceSearchQuery::And(value)
142                    }
143                    Variant_::Or => {
144                        let value = map.next_value()?;
145                        ResourceSearchQuery::Or(value)
146                    }
147                    Variant_::Not => {
148                        let value = map.next_value()?;
149                        ResourceSearchQuery::Not(value)
150                    }
151                    Variant_::Unknown(type_) => {
152                        let value = map.next_value()?;
153                        ResourceSearchQuery::Unknown(Unknown {
154                            type_: type_.clone(),
155                            value,
156                        })
157                    }
158                };
159                if map.next_key::<UnionTypeField_>()?.is_none() {
160                    return Err(de::Error::missing_field("type"));
161                }
162                let type_variant = map.next_value::<Variant_>()?;
163                if variant != type_variant {
164                    return Err(
165                        de::Error::invalid_value(
166                            de::Unexpected::Str(type_variant.as_str()),
167                            &variant.as_str(),
168                        ),
169                    );
170                }
171                value
172            }
173            None => return Err(de::Error::missing_field("type")),
174        };
175        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
176            return Err(de::Error::invalid_length(3, &"type and value fields"));
177        }
178        Ok(v)
179    }
180}
181#[derive(PartialEq)]
182enum Variant_ {
183    Properties,
184    Labels,
185    Workspace,
186    And,
187    Or,
188    Not,
189    Unknown(Box<str>),
190}
191impl Variant_ {
192    fn as_str(&self) -> &'static str {
193        match *self {
194            Variant_::Properties => "properties",
195            Variant_::Labels => "labels",
196            Variant_::Workspace => "workspace",
197            Variant_::And => "and",
198            Variant_::Or => "or",
199            Variant_::Not => "not",
200            Variant_::Unknown(_) => "unknown variant",
201        }
202    }
203}
204impl<'de> de::Deserialize<'de> for Variant_ {
205    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
206    where
207        D: de::Deserializer<'de>,
208    {
209        d.deserialize_str(VariantVisitor_)
210    }
211}
212struct VariantVisitor_;
213impl<'de> de::Visitor<'de> for VariantVisitor_ {
214    type Value = Variant_;
215    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
216        fmt.write_str("string")
217    }
218    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
219    where
220        E: de::Error,
221    {
222        let v = match value {
223            "properties" => Variant_::Properties,
224            "labels" => Variant_::Labels,
225            "workspace" => Variant_::Workspace,
226            "and" => Variant_::And,
227            "or" => Variant_::Or,
228            "not" => Variant_::Not,
229            value => Variant_::Unknown(value.to_string().into_boxed_str()),
230        };
231        Ok(v)
232    }
233}
234///An unknown variant of the ResourceSearchQuery union.
235#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
236pub struct Unknown {
237    type_: Box<str>,
238    value: conjure_object::Any,
239}
240impl Unknown {
241    /// Returns the unknown variant's type name.
242    #[inline]
243    pub fn type_(&self) -> &str {
244        &self.type_
245    }
246}