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