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