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