nominal_api/conjure/objects/timeseries/metadata/api/
locator_template.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 LocatorTemplate {
7 TimescaleDb(super::TimescaleDbLocatorTemplate),
8 Influx(super::Influx2LocatorTemplate),
9 Influx1(super::Influx1LocatorTemplate),
10 Nominal(super::NominalLocatorTemplate),
11 Timestream(super::TimestreamLocatorTemplate),
12 VisualCrossing(super::VisualCrossingLocatorTemplate),
13 BigQuery(super::BigQueryLocatorTemplate),
14 Api(super::ApiLocatorTemplate),
15 Video(super::VideoLocatorTemplate),
16 Spatial(super::SpatialLocatorTemplate),
17 Unknown(Unknown),
19}
20impl ser::Serialize for LocatorTemplate {
21 fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
22 where
23 S: ser::Serializer,
24 {
25 let mut map = s.serialize_map(Some(2))?;
26 match self {
27 LocatorTemplate::TimescaleDb(value) => {
28 map.serialize_entry(&"type", &"timescaleDb")?;
29 map.serialize_entry(&"timescaleDb", value)?;
30 }
31 LocatorTemplate::Influx(value) => {
32 map.serialize_entry(&"type", &"influx")?;
33 map.serialize_entry(&"influx", value)?;
34 }
35 LocatorTemplate::Influx1(value) => {
36 map.serialize_entry(&"type", &"influx1")?;
37 map.serialize_entry(&"influx1", value)?;
38 }
39 LocatorTemplate::Nominal(value) => {
40 map.serialize_entry(&"type", &"nominal")?;
41 map.serialize_entry(&"nominal", value)?;
42 }
43 LocatorTemplate::Timestream(value) => {
44 map.serialize_entry(&"type", &"timestream")?;
45 map.serialize_entry(&"timestream", value)?;
46 }
47 LocatorTemplate::VisualCrossing(value) => {
48 map.serialize_entry(&"type", &"visualCrossing")?;
49 map.serialize_entry(&"visualCrossing", value)?;
50 }
51 LocatorTemplate::BigQuery(value) => {
52 map.serialize_entry(&"type", &"bigQuery")?;
53 map.serialize_entry(&"bigQuery", value)?;
54 }
55 LocatorTemplate::Api(value) => {
56 map.serialize_entry(&"type", &"api")?;
57 map.serialize_entry(&"api", value)?;
58 }
59 LocatorTemplate::Video(value) => {
60 map.serialize_entry(&"type", &"video")?;
61 map.serialize_entry(&"video", value)?;
62 }
63 LocatorTemplate::Spatial(value) => {
64 map.serialize_entry(&"type", &"spatial")?;
65 map.serialize_entry(&"spatial", value)?;
66 }
67 LocatorTemplate::Unknown(value) => {
68 map.serialize_entry(&"type", &value.type_)?;
69 map.serialize_entry(&value.type_, &value.value)?;
70 }
71 }
72 map.end()
73 }
74}
75impl<'de> de::Deserialize<'de> for LocatorTemplate {
76 fn deserialize<D>(d: D) -> Result<LocatorTemplate, D::Error>
77 where
78 D: de::Deserializer<'de>,
79 {
80 d.deserialize_map(Visitor_)
81 }
82}
83struct Visitor_;
84impl<'de> de::Visitor<'de> for Visitor_ {
85 type Value = LocatorTemplate;
86 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
87 fmt.write_str("union LocatorTemplate")
88 }
89 fn visit_map<A>(self, mut map: A) -> Result<LocatorTemplate, A::Error>
90 where
91 A: de::MapAccess<'de>,
92 {
93 let v = match map.next_key::<UnionField_<Variant_>>()? {
94 Some(UnionField_::Type) => {
95 let variant = map.next_value()?;
96 let key = map.next_key()?;
97 match (variant, key) {
98 (Variant_::TimescaleDb, Some(Variant_::TimescaleDb)) => {
99 let value = map.next_value()?;
100 LocatorTemplate::TimescaleDb(value)
101 }
102 (Variant_::Influx, Some(Variant_::Influx)) => {
103 let value = map.next_value()?;
104 LocatorTemplate::Influx(value)
105 }
106 (Variant_::Influx1, Some(Variant_::Influx1)) => {
107 let value = map.next_value()?;
108 LocatorTemplate::Influx1(value)
109 }
110 (Variant_::Nominal, Some(Variant_::Nominal)) => {
111 let value = map.next_value()?;
112 LocatorTemplate::Nominal(value)
113 }
114 (Variant_::Timestream, Some(Variant_::Timestream)) => {
115 let value = map.next_value()?;
116 LocatorTemplate::Timestream(value)
117 }
118 (Variant_::VisualCrossing, Some(Variant_::VisualCrossing)) => {
119 let value = map.next_value()?;
120 LocatorTemplate::VisualCrossing(value)
121 }
122 (Variant_::BigQuery, Some(Variant_::BigQuery)) => {
123 let value = map.next_value()?;
124 LocatorTemplate::BigQuery(value)
125 }
126 (Variant_::Api, Some(Variant_::Api)) => {
127 let value = map.next_value()?;
128 LocatorTemplate::Api(value)
129 }
130 (Variant_::Video, Some(Variant_::Video)) => {
131 let value = map.next_value()?;
132 LocatorTemplate::Video(value)
133 }
134 (Variant_::Spatial, Some(Variant_::Spatial)) => {
135 let value = map.next_value()?;
136 LocatorTemplate::Spatial(value)
137 }
138 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
139 if type_ == b {
140 let value = map.next_value()?;
141 LocatorTemplate::Unknown(Unknown { type_, value })
142 } else {
143 return Err(
144 de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
145 )
146 }
147 }
148 (variant, Some(key)) => {
149 return Err(
150 de::Error::invalid_value(
151 de::Unexpected::Str(key.as_str()),
152 &variant.as_str(),
153 ),
154 );
155 }
156 (variant, None) => {
157 return Err(de::Error::missing_field(variant.as_str()));
158 }
159 }
160 }
161 Some(UnionField_::Value(variant)) => {
162 let value = match &variant {
163 Variant_::TimescaleDb => {
164 let value = map.next_value()?;
165 LocatorTemplate::TimescaleDb(value)
166 }
167 Variant_::Influx => {
168 let value = map.next_value()?;
169 LocatorTemplate::Influx(value)
170 }
171 Variant_::Influx1 => {
172 let value = map.next_value()?;
173 LocatorTemplate::Influx1(value)
174 }
175 Variant_::Nominal => {
176 let value = map.next_value()?;
177 LocatorTemplate::Nominal(value)
178 }
179 Variant_::Timestream => {
180 let value = map.next_value()?;
181 LocatorTemplate::Timestream(value)
182 }
183 Variant_::VisualCrossing => {
184 let value = map.next_value()?;
185 LocatorTemplate::VisualCrossing(value)
186 }
187 Variant_::BigQuery => {
188 let value = map.next_value()?;
189 LocatorTemplate::BigQuery(value)
190 }
191 Variant_::Api => {
192 let value = map.next_value()?;
193 LocatorTemplate::Api(value)
194 }
195 Variant_::Video => {
196 let value = map.next_value()?;
197 LocatorTemplate::Video(value)
198 }
199 Variant_::Spatial => {
200 let value = map.next_value()?;
201 LocatorTemplate::Spatial(value)
202 }
203 Variant_::Unknown(type_) => {
204 let value = map.next_value()?;
205 LocatorTemplate::Unknown(Unknown {
206 type_: type_.clone(),
207 value,
208 })
209 }
210 };
211 if map.next_key::<UnionTypeField_>()?.is_none() {
212 return Err(de::Error::missing_field("type"));
213 }
214 let type_variant = map.next_value::<Variant_>()?;
215 if variant != type_variant {
216 return Err(
217 de::Error::invalid_value(
218 de::Unexpected::Str(type_variant.as_str()),
219 &variant.as_str(),
220 ),
221 );
222 }
223 value
224 }
225 None => return Err(de::Error::missing_field("type")),
226 };
227 if map.next_key::<UnionField_<Variant_>>()?.is_some() {
228 return Err(de::Error::invalid_length(3, &"type and value fields"));
229 }
230 Ok(v)
231 }
232}
233#[derive(PartialEq)]
234enum Variant_ {
235 TimescaleDb,
236 Influx,
237 Influx1,
238 Nominal,
239 Timestream,
240 VisualCrossing,
241 BigQuery,
242 Api,
243 Video,
244 Spatial,
245 Unknown(Box<str>),
246}
247impl Variant_ {
248 fn as_str(&self) -> &'static str {
249 match *self {
250 Variant_::TimescaleDb => "timescaleDb",
251 Variant_::Influx => "influx",
252 Variant_::Influx1 => "influx1",
253 Variant_::Nominal => "nominal",
254 Variant_::Timestream => "timestream",
255 Variant_::VisualCrossing => "visualCrossing",
256 Variant_::BigQuery => "bigQuery",
257 Variant_::Api => "api",
258 Variant_::Video => "video",
259 Variant_::Spatial => "spatial",
260 Variant_::Unknown(_) => "unknown variant",
261 }
262 }
263}
264impl<'de> de::Deserialize<'de> for Variant_ {
265 fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
266 where
267 D: de::Deserializer<'de>,
268 {
269 d.deserialize_str(VariantVisitor_)
270 }
271}
272struct VariantVisitor_;
273impl<'de> de::Visitor<'de> for VariantVisitor_ {
274 type Value = Variant_;
275 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
276 fmt.write_str("string")
277 }
278 fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
279 where
280 E: de::Error,
281 {
282 let v = match value {
283 "timescaleDb" => Variant_::TimescaleDb,
284 "influx" => Variant_::Influx,
285 "influx1" => Variant_::Influx1,
286 "nominal" => Variant_::Nominal,
287 "timestream" => Variant_::Timestream,
288 "visualCrossing" => Variant_::VisualCrossing,
289 "bigQuery" => Variant_::BigQuery,
290 "api" => Variant_::Api,
291 "video" => Variant_::Video,
292 "spatial" => Variant_::Spatial,
293 value => Variant_::Unknown(value.to_string().into_boxed_str()),
294 };
295 Ok(v)
296 }
297}
298#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
300pub struct Unknown {
301 type_: Box<str>,
302 value: conjure_object::Any,
303}
304impl Unknown {
305 #[inline]
307 pub fn type_(&self) -> &str {
308 &self.type_
309 }
310}