nominal_api/conjure/objects/scout/chartdefinition/api/
table_column_log_aggregation.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 TableColumnLogAggregation {
7 Count(super::NoConfigAggregation),
8 Unknown(Unknown),
10}
11impl ser::Serialize for TableColumnLogAggregation {
12 fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
13 where
14 S: ser::Serializer,
15 {
16 let mut map = s.serialize_map(Some(2))?;
17 match self {
18 TableColumnLogAggregation::Count(value) => {
19 map.serialize_entry(&"type", &"count")?;
20 map.serialize_entry(&"count", value)?;
21 }
22 TableColumnLogAggregation::Unknown(value) => {
23 map.serialize_entry(&"type", &value.type_)?;
24 map.serialize_entry(&value.type_, &value.value)?;
25 }
26 }
27 map.end()
28 }
29}
30impl<'de> de::Deserialize<'de> for TableColumnLogAggregation {
31 fn deserialize<D>(d: D) -> Result<TableColumnLogAggregation, D::Error>
32 where
33 D: de::Deserializer<'de>,
34 {
35 d.deserialize_map(Visitor_)
36 }
37}
38struct Visitor_;
39impl<'de> de::Visitor<'de> for Visitor_ {
40 type Value = TableColumnLogAggregation;
41 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
42 fmt.write_str("union TableColumnLogAggregation")
43 }
44 fn visit_map<A>(self, mut map: A) -> Result<TableColumnLogAggregation, A::Error>
45 where
46 A: de::MapAccess<'de>,
47 {
48 let v = match map.next_key::<UnionField_<Variant_>>()? {
49 Some(UnionField_::Type) => {
50 let variant = map.next_value()?;
51 let key = map.next_key()?;
52 match (variant, key) {
53 (Variant_::Count, Some(Variant_::Count)) => {
54 let value = map.next_value()?;
55 TableColumnLogAggregation::Count(value)
56 }
57 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
58 if type_ == b {
59 let value = map.next_value()?;
60 TableColumnLogAggregation::Unknown(Unknown { type_, value })
61 } else {
62 return Err(
63 de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
64 )
65 }
66 }
67 (variant, Some(key)) => {
68 return Err(
69 de::Error::invalid_value(
70 de::Unexpected::Str(key.as_str()),
71 &variant.as_str(),
72 ),
73 );
74 }
75 (variant, None) => {
76 return Err(de::Error::missing_field(variant.as_str()));
77 }
78 }
79 }
80 Some(UnionField_::Value(variant)) => {
81 let value = match &variant {
82 Variant_::Count => {
83 let value = map.next_value()?;
84 TableColumnLogAggregation::Count(value)
85 }
86 Variant_::Unknown(type_) => {
87 let value = map.next_value()?;
88 TableColumnLogAggregation::Unknown(Unknown {
89 type_: type_.clone(),
90 value,
91 })
92 }
93 };
94 if map.next_key::<UnionTypeField_>()?.is_none() {
95 return Err(de::Error::missing_field("type"));
96 }
97 let type_variant = map.next_value::<Variant_>()?;
98 if variant != type_variant {
99 return Err(
100 de::Error::invalid_value(
101 de::Unexpected::Str(type_variant.as_str()),
102 &variant.as_str(),
103 ),
104 );
105 }
106 value
107 }
108 None => return Err(de::Error::missing_field("type")),
109 };
110 if map.next_key::<UnionField_<Variant_>>()?.is_some() {
111 return Err(de::Error::invalid_length(3, &"type and value fields"));
112 }
113 Ok(v)
114 }
115}
116#[derive(PartialEq)]
117enum Variant_ {
118 Count,
119 Unknown(Box<str>),
120}
121impl Variant_ {
122 fn as_str(&self) -> &'static str {
123 match *self {
124 Variant_::Count => "count",
125 Variant_::Unknown(_) => "unknown variant",
126 }
127 }
128}
129impl<'de> de::Deserialize<'de> for Variant_ {
130 fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
131 where
132 D: de::Deserializer<'de>,
133 {
134 d.deserialize_str(VariantVisitor_)
135 }
136}
137struct VariantVisitor_;
138impl<'de> de::Visitor<'de> for VariantVisitor_ {
139 type Value = Variant_;
140 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
141 fmt.write_str("string")
142 }
143 fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
144 where
145 E: de::Error,
146 {
147 let v = match value {
148 "count" => Variant_::Count,
149 value => Variant_::Unknown(value.to_string().into_boxed_str()),
150 };
151 Ok(v)
152 }
153}
154#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
156pub struct Unknown {
157 type_: Box<str>,
158 value: conjure_object::Any,
159}
160impl Unknown {
161 #[inline]
163 pub fn type_(&self) -> &str {
164 &self.type_
165 }
166}