Skip to main content

nominal_api/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    ToStartOfInterval(super::Numeric1dArrayToStartOfIntervalSeries),
13    FilterByTag(super::Numeric1dArrayTagFilterSeries),
14    SelectTags(super::Numeric1dArraySelectTagsSeries),
15    /// An unknown variant.
16    Unknown(Unknown),
17}
18impl ser::Serialize for Numeric1dArraySeries {
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            Numeric1dArraySeries::Channel(value) => {
26                map.serialize_entry(&"type", &"channel")?;
27                map.serialize_entry(&"channel", value)?;
28            }
29            Numeric1dArraySeries::Raw(value) => {
30                map.serialize_entry(&"type", &"raw")?;
31                map.serialize_entry(&"raw", value)?;
32            }
33            Numeric1dArraySeries::Derived(value) => {
34                map.serialize_entry(&"type", &"derived")?;
35                map.serialize_entry(&"derived", value)?;
36            }
37            Numeric1dArraySeries::SelectNumeric1dArray(value) => {
38                map.serialize_entry(&"type", &"selectNumeric1dArray")?;
39                map.serialize_entry(&"selectNumeric1dArray", value)?;
40            }
41            Numeric1dArraySeries::ToStartOfInterval(value) => {
42                map.serialize_entry(&"type", &"toStartOfInterval")?;
43                map.serialize_entry(&"toStartOfInterval", value)?;
44            }
45            Numeric1dArraySeries::FilterByTag(value) => {
46                map.serialize_entry(&"type", &"filterByTag")?;
47                map.serialize_entry(&"filterByTag", value)?;
48            }
49            Numeric1dArraySeries::SelectTags(value) => {
50                map.serialize_entry(&"type", &"selectTags")?;
51                map.serialize_entry(&"selectTags", value)?;
52            }
53            Numeric1dArraySeries::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 Numeric1dArraySeries {
62    fn deserialize<D>(d: D) -> Result<Numeric1dArraySeries, 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 = Numeric1dArraySeries;
72    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
73        fmt.write_str("union Numeric1dArraySeries")
74    }
75    fn visit_map<A>(self, mut map: A) -> Result<Numeric1dArraySeries, 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_::Channel, Some(Variant_::Channel)) => {
85                        let value = map.next_value()?;
86                        Numeric1dArraySeries::Channel(value)
87                    }
88                    (Variant_::Raw, Some(Variant_::Raw)) => {
89                        let value = map.next_value()?;
90                        Numeric1dArraySeries::Raw(value)
91                    }
92                    (Variant_::Derived, Some(Variant_::Derived)) => {
93                        let value = map.next_value()?;
94                        Numeric1dArraySeries::Derived(value)
95                    }
96                    (
97                        Variant_::SelectNumeric1dArray,
98                        Some(Variant_::SelectNumeric1dArray),
99                    ) => {
100                        let value = map.next_value()?;
101                        Numeric1dArraySeries::SelectNumeric1dArray(value)
102                    }
103                    (Variant_::ToStartOfInterval, Some(Variant_::ToStartOfInterval)) => {
104                        let value = map.next_value()?;
105                        Numeric1dArraySeries::ToStartOfInterval(value)
106                    }
107                    (Variant_::FilterByTag, Some(Variant_::FilterByTag)) => {
108                        let value = map.next_value()?;
109                        Numeric1dArraySeries::FilterByTag(value)
110                    }
111                    (Variant_::SelectTags, Some(Variant_::SelectTags)) => {
112                        let value = map.next_value()?;
113                        Numeric1dArraySeries::SelectTags(value)
114                    }
115                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
116                        if type_ == b {
117                            let value = map.next_value()?;
118                            Numeric1dArraySeries::Unknown(Unknown { type_, value })
119                        } else {
120                            return Err(
121                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
122                            )
123                        }
124                    }
125                    (variant, Some(key)) => {
126                        return Err(
127                            de::Error::invalid_value(
128                                de::Unexpected::Str(key.as_str()),
129                                &variant.as_str(),
130                            ),
131                        );
132                    }
133                    (variant, None) => {
134                        return Err(de::Error::missing_field(variant.as_str()));
135                    }
136                }
137            }
138            Some(UnionField_::Value(variant)) => {
139                let value = match &variant {
140                    Variant_::Channel => {
141                        let value = map.next_value()?;
142                        Numeric1dArraySeries::Channel(value)
143                    }
144                    Variant_::Raw => {
145                        let value = map.next_value()?;
146                        Numeric1dArraySeries::Raw(value)
147                    }
148                    Variant_::Derived => {
149                        let value = map.next_value()?;
150                        Numeric1dArraySeries::Derived(value)
151                    }
152                    Variant_::SelectNumeric1dArray => {
153                        let value = map.next_value()?;
154                        Numeric1dArraySeries::SelectNumeric1dArray(value)
155                    }
156                    Variant_::ToStartOfInterval => {
157                        let value = map.next_value()?;
158                        Numeric1dArraySeries::ToStartOfInterval(value)
159                    }
160                    Variant_::FilterByTag => {
161                        let value = map.next_value()?;
162                        Numeric1dArraySeries::FilterByTag(value)
163                    }
164                    Variant_::SelectTags => {
165                        let value = map.next_value()?;
166                        Numeric1dArraySeries::SelectTags(value)
167                    }
168                    Variant_::Unknown(type_) => {
169                        let value = map.next_value()?;
170                        Numeric1dArraySeries::Unknown(Unknown {
171                            type_: type_.clone(),
172                            value,
173                        })
174                    }
175                };
176                if map.next_key::<UnionTypeField_>()?.is_none() {
177                    return Err(de::Error::missing_field("type"));
178                }
179                let type_variant = map.next_value::<Variant_>()?;
180                if variant != type_variant {
181                    return Err(
182                        de::Error::invalid_value(
183                            de::Unexpected::Str(type_variant.as_str()),
184                            &variant.as_str(),
185                        ),
186                    );
187                }
188                value
189            }
190            None => return Err(de::Error::missing_field("type")),
191        };
192        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
193            return Err(de::Error::invalid_length(3, &"type and value fields"));
194        }
195        Ok(v)
196    }
197}
198#[derive(PartialEq)]
199enum Variant_ {
200    Channel,
201    Raw,
202    Derived,
203    SelectNumeric1dArray,
204    ToStartOfInterval,
205    FilterByTag,
206    SelectTags,
207    Unknown(Box<str>),
208}
209impl Variant_ {
210    fn as_str(&self) -> &'static str {
211        match *self {
212            Variant_::Channel => "channel",
213            Variant_::Raw => "raw",
214            Variant_::Derived => "derived",
215            Variant_::SelectNumeric1dArray => "selectNumeric1dArray",
216            Variant_::ToStartOfInterval => "toStartOfInterval",
217            Variant_::FilterByTag => "filterByTag",
218            Variant_::SelectTags => "selectTags",
219            Variant_::Unknown(_) => "unknown variant",
220        }
221    }
222}
223impl<'de> de::Deserialize<'de> for Variant_ {
224    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
225    where
226        D: de::Deserializer<'de>,
227    {
228        d.deserialize_str(VariantVisitor_)
229    }
230}
231struct VariantVisitor_;
232impl<'de> de::Visitor<'de> for VariantVisitor_ {
233    type Value = Variant_;
234    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
235        fmt.write_str("string")
236    }
237    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
238    where
239        E: de::Error,
240    {
241        let v = match value {
242            "channel" => Variant_::Channel,
243            "raw" => Variant_::Raw,
244            "derived" => Variant_::Derived,
245            "selectNumeric1dArray" => Variant_::SelectNumeric1dArray,
246            "toStartOfInterval" => Variant_::ToStartOfInterval,
247            "filterByTag" => Variant_::FilterByTag,
248            "selectTags" => Variant_::SelectTags,
249            value => Variant_::Unknown(value.to_string().into_boxed_str()),
250        };
251        Ok(v)
252    }
253}
254///An unknown variant of the Numeric1dArraySeries union.
255#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
256pub struct Unknown {
257    type_: Box<str>,
258    value: conjure_object::Any,
259}
260impl Unknown {
261    /// Returns the unknown variant's type name.
262    #[inline]
263    pub fn type_(&self) -> &str {
264        &self.type_
265    }
266}