Skip to main content

nominal_api/conjure/objects/scout/datasource/connection/api/
connection_details.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 ConnectionDetails {
7    Timescale(super::TimescaleConnectionDetails),
8    Influx(super::Influx2ConnectionDetails),
9    Influx1(super::Influx1ConnectionDetails),
10    Nominal(super::NominalConnectionDetails),
11    Timestream(super::TimestreamConnectionDetails),
12    VisualCrossing(super::VisualCrossingConnectionDetails),
13    BigQuery(super::BigQueryConnectionDetails),
14    Api(super::ApiConnectionDetails),
15    /// An unknown variant.
16    Unknown(Unknown),
17}
18impl ser::Serialize for ConnectionDetails {
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            ConnectionDetails::Timescale(value) => {
26                map.serialize_entry(&"type", &"timescale")?;
27                map.serialize_entry(&"timescale", value)?;
28            }
29            ConnectionDetails::Influx(value) => {
30                map.serialize_entry(&"type", &"influx")?;
31                map.serialize_entry(&"influx", value)?;
32            }
33            ConnectionDetails::Influx1(value) => {
34                map.serialize_entry(&"type", &"influx1")?;
35                map.serialize_entry(&"influx1", value)?;
36            }
37            ConnectionDetails::Nominal(value) => {
38                map.serialize_entry(&"type", &"nominal")?;
39                map.serialize_entry(&"nominal", value)?;
40            }
41            ConnectionDetails::Timestream(value) => {
42                map.serialize_entry(&"type", &"timestream")?;
43                map.serialize_entry(&"timestream", value)?;
44            }
45            ConnectionDetails::VisualCrossing(value) => {
46                map.serialize_entry(&"type", &"visualCrossing")?;
47                map.serialize_entry(&"visualCrossing", value)?;
48            }
49            ConnectionDetails::BigQuery(value) => {
50                map.serialize_entry(&"type", &"bigQuery")?;
51                map.serialize_entry(&"bigQuery", value)?;
52            }
53            ConnectionDetails::Api(value) => {
54                map.serialize_entry(&"type", &"api")?;
55                map.serialize_entry(&"api", value)?;
56            }
57            ConnectionDetails::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 ConnectionDetails {
66    fn deserialize<D>(d: D) -> Result<ConnectionDetails, 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 = ConnectionDetails;
76    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
77        fmt.write_str("union ConnectionDetails")
78    }
79    fn visit_map<A>(self, mut map: A) -> Result<ConnectionDetails, 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_::Timescale, Some(Variant_::Timescale)) => {
89                        let value = map.next_value()?;
90                        ConnectionDetails::Timescale(value)
91                    }
92                    (Variant_::Influx, Some(Variant_::Influx)) => {
93                        let value = map.next_value()?;
94                        ConnectionDetails::Influx(value)
95                    }
96                    (Variant_::Influx1, Some(Variant_::Influx1)) => {
97                        let value = map.next_value()?;
98                        ConnectionDetails::Influx1(value)
99                    }
100                    (Variant_::Nominal, Some(Variant_::Nominal)) => {
101                        let value = map.next_value()?;
102                        ConnectionDetails::Nominal(value)
103                    }
104                    (Variant_::Timestream, Some(Variant_::Timestream)) => {
105                        let value = map.next_value()?;
106                        ConnectionDetails::Timestream(value)
107                    }
108                    (Variant_::VisualCrossing, Some(Variant_::VisualCrossing)) => {
109                        let value = map.next_value()?;
110                        ConnectionDetails::VisualCrossing(value)
111                    }
112                    (Variant_::BigQuery, Some(Variant_::BigQuery)) => {
113                        let value = map.next_value()?;
114                        ConnectionDetails::BigQuery(value)
115                    }
116                    (Variant_::Api, Some(Variant_::Api)) => {
117                        let value = map.next_value()?;
118                        ConnectionDetails::Api(value)
119                    }
120                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
121                        if type_ == b {
122                            let value = map.next_value()?;
123                            ConnectionDetails::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_::Timescale => {
146                        let value = map.next_value()?;
147                        ConnectionDetails::Timescale(value)
148                    }
149                    Variant_::Influx => {
150                        let value = map.next_value()?;
151                        ConnectionDetails::Influx(value)
152                    }
153                    Variant_::Influx1 => {
154                        let value = map.next_value()?;
155                        ConnectionDetails::Influx1(value)
156                    }
157                    Variant_::Nominal => {
158                        let value = map.next_value()?;
159                        ConnectionDetails::Nominal(value)
160                    }
161                    Variant_::Timestream => {
162                        let value = map.next_value()?;
163                        ConnectionDetails::Timestream(value)
164                    }
165                    Variant_::VisualCrossing => {
166                        let value = map.next_value()?;
167                        ConnectionDetails::VisualCrossing(value)
168                    }
169                    Variant_::BigQuery => {
170                        let value = map.next_value()?;
171                        ConnectionDetails::BigQuery(value)
172                    }
173                    Variant_::Api => {
174                        let value = map.next_value()?;
175                        ConnectionDetails::Api(value)
176                    }
177                    Variant_::Unknown(type_) => {
178                        let value = map.next_value()?;
179                        ConnectionDetails::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    Timescale,
210    Influx,
211    Influx1,
212    Nominal,
213    Timestream,
214    VisualCrossing,
215    BigQuery,
216    Api,
217    Unknown(Box<str>),
218}
219impl Variant_ {
220    fn as_str(&self) -> &'static str {
221        match *self {
222            Variant_::Timescale => "timescale",
223            Variant_::Influx => "influx",
224            Variant_::Influx1 => "influx1",
225            Variant_::Nominal => "nominal",
226            Variant_::Timestream => "timestream",
227            Variant_::VisualCrossing => "visualCrossing",
228            Variant_::BigQuery => "bigQuery",
229            Variant_::Api => "api",
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            "timescale" => Variant_::Timescale,
254            "influx" => Variant_::Influx,
255            "influx1" => Variant_::Influx1,
256            "nominal" => Variant_::Nominal,
257            "timestream" => Variant_::Timestream,
258            "visualCrossing" => Variant_::VisualCrossing,
259            "bigQuery" => Variant_::BigQuery,
260            "api" => Variant_::Api,
261            value => Variant_::Unknown(value.to_string().into_boxed_str()),
262        };
263        Ok(v)
264    }
265}
266///An unknown variant of the ConnectionDetails union.
267#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
268pub struct Unknown {
269    type_: Box<str>,
270    value: conjure_object::Any,
271}
272impl Unknown {
273    /// Returns the unknown variant's type name.
274    #[inline]
275    pub fn type_(&self) -> &str {
276        &self.type_
277    }
278}