Skip to main content

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