nominal_api_conjure/conjure/objects/scout/compute/api/
compute_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 ComputeNode {
8 Enum(Box<super::EnumSeries>),
9 Numeric(Box<super::NumericSeries>),
10 Log(Box<super::LogSeries>),
11 Ranges(Box<super::RangeSeries>),
12 Array(Box<super::ArraySeries>),
13 Struct(Box<super::StructSeries>),
14 CurveFit(super::CurveFit),
15 Video(super::Reference),
16 #[deprecated(note = "wrap raw references in a typed compute node.")]
17 Raw(super::Reference),
18 Unknown(Unknown),
20}
21impl ser::Serialize for ComputeNode {
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 ComputeNode::Enum(value) => {
29 map.serialize_entry(&"type", &"enum")?;
30 map.serialize_entry(&"enum", value)?;
31 }
32 ComputeNode::Numeric(value) => {
33 map.serialize_entry(&"type", &"numeric")?;
34 map.serialize_entry(&"numeric", value)?;
35 }
36 ComputeNode::Log(value) => {
37 map.serialize_entry(&"type", &"log")?;
38 map.serialize_entry(&"log", value)?;
39 }
40 ComputeNode::Ranges(value) => {
41 map.serialize_entry(&"type", &"ranges")?;
42 map.serialize_entry(&"ranges", value)?;
43 }
44 ComputeNode::Array(value) => {
45 map.serialize_entry(&"type", &"array")?;
46 map.serialize_entry(&"array", value)?;
47 }
48 ComputeNode::Struct(value) => {
49 map.serialize_entry(&"type", &"struct")?;
50 map.serialize_entry(&"struct", value)?;
51 }
52 ComputeNode::CurveFit(value) => {
53 map.serialize_entry(&"type", &"curveFit")?;
54 map.serialize_entry(&"curveFit", value)?;
55 }
56 ComputeNode::Video(value) => {
57 map.serialize_entry(&"type", &"video")?;
58 map.serialize_entry(&"video", value)?;
59 }
60 #[allow(deprecated)]
61 ComputeNode::Raw(value) => {
62 map.serialize_entry(&"type", &"raw")?;
63 map.serialize_entry(&"raw", value)?;
64 }
65 ComputeNode::Unknown(value) => {
66 map.serialize_entry(&"type", &value.type_)?;
67 map.serialize_entry(&value.type_, &value.value)?;
68 }
69 }
70 map.end()
71 }
72}
73impl<'de> de::Deserialize<'de> for ComputeNode {
74 fn deserialize<D>(d: D) -> Result<ComputeNode, D::Error>
75 where
76 D: de::Deserializer<'de>,
77 {
78 d.deserialize_map(Visitor_)
79 }
80}
81struct Visitor_;
82impl<'de> de::Visitor<'de> for Visitor_ {
83 type Value = ComputeNode;
84 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
85 fmt.write_str("union ComputeNode")
86 }
87 fn visit_map<A>(self, mut map: A) -> Result<ComputeNode, A::Error>
88 where
89 A: de::MapAccess<'de>,
90 {
91 let v = match map.next_key::<UnionField_<Variant_>>()? {
92 Some(UnionField_::Type) => {
93 let variant = map.next_value()?;
94 let key = map.next_key()?;
95 match (variant, key) {
96 (Variant_::Enum, Some(Variant_::Enum)) => {
97 let value = map.next_value()?;
98 ComputeNode::Enum(value)
99 }
100 (Variant_::Numeric, Some(Variant_::Numeric)) => {
101 let value = map.next_value()?;
102 ComputeNode::Numeric(value)
103 }
104 (Variant_::Log, Some(Variant_::Log)) => {
105 let value = map.next_value()?;
106 ComputeNode::Log(value)
107 }
108 (Variant_::Ranges, Some(Variant_::Ranges)) => {
109 let value = map.next_value()?;
110 ComputeNode::Ranges(value)
111 }
112 (Variant_::Array, Some(Variant_::Array)) => {
113 let value = map.next_value()?;
114 ComputeNode::Array(value)
115 }
116 (Variant_::Struct, Some(Variant_::Struct)) => {
117 let value = map.next_value()?;
118 ComputeNode::Struct(value)
119 }
120 (Variant_::CurveFit, Some(Variant_::CurveFit)) => {
121 let value = map.next_value()?;
122 ComputeNode::CurveFit(value)
123 }
124 (Variant_::Video, Some(Variant_::Video)) => {
125 let value = map.next_value()?;
126 ComputeNode::Video(value)
127 }
128 #[allow(deprecated)]
129 (Variant_::Raw, Some(Variant_::Raw)) => {
130 let value = map.next_value()?;
131 ComputeNode::Raw(value)
132 }
133 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
134 if type_ == b {
135 let value = map.next_value()?;
136 ComputeNode::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_::Enum => {
159 let value = map.next_value()?;
160 ComputeNode::Enum(value)
161 }
162 Variant_::Numeric => {
163 let value = map.next_value()?;
164 ComputeNode::Numeric(value)
165 }
166 Variant_::Log => {
167 let value = map.next_value()?;
168 ComputeNode::Log(value)
169 }
170 Variant_::Ranges => {
171 let value = map.next_value()?;
172 ComputeNode::Ranges(value)
173 }
174 Variant_::Array => {
175 let value = map.next_value()?;
176 ComputeNode::Array(value)
177 }
178 Variant_::Struct => {
179 let value = map.next_value()?;
180 ComputeNode::Struct(value)
181 }
182 Variant_::CurveFit => {
183 let value = map.next_value()?;
184 ComputeNode::CurveFit(value)
185 }
186 Variant_::Video => {
187 let value = map.next_value()?;
188 ComputeNode::Video(value)
189 }
190 Variant_::Raw => {
191 let value = map.next_value()?;
192 #[allow(deprecated)] ComputeNode::Raw(value)
193 }
194 Variant_::Unknown(type_) => {
195 let value = map.next_value()?;
196 ComputeNode::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 Enum,
227 Numeric,
228 Log,
229 Ranges,
230 Array,
231 Struct,
232 CurveFit,
233 Video,
234 Raw,
235 Unknown(Box<str>),
236}
237impl Variant_ {
238 fn as_str(&self) -> &'static str {
239 match *self {
240 Variant_::Enum => "enum",
241 Variant_::Numeric => "numeric",
242 Variant_::Log => "log",
243 Variant_::Ranges => "ranges",
244 Variant_::Array => "array",
245 Variant_::Struct => "struct",
246 Variant_::CurveFit => "curveFit",
247 Variant_::Video => "video",
248 Variant_::Raw => "raw",
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 "enum" => Variant_::Enum,
273 "numeric" => Variant_::Numeric,
274 "log" => Variant_::Log,
275 "ranges" => Variant_::Ranges,
276 "array" => Variant_::Array,
277 "struct" => Variant_::Struct,
278 "curveFit" => Variant_::CurveFit,
279 "video" => Variant_::Video,
280 "raw" => Variant_::Raw,
281 value => Variant_::Unknown(value.to_string().into_boxed_str()),
282 };
283 Ok(v)
284 }
285}
286#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
288pub struct Unknown {
289 type_: Box<str>,
290 value: conjure_object::Any,
291}
292impl Unknown {
293 #[inline]
295 pub fn type_(&self) -> &str {
296 &self.type_
297 }
298}