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