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