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