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