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