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