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