nominal_api/conjure/objects/scout/datareview/api/
histogram_distribution_variable.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 HistogramDistributionVariable {
7 StartTime(super::HistogramStartTimeVariable),
8 Unknown(Unknown),
10}
11impl ser::Serialize for HistogramDistributionVariable {
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 HistogramDistributionVariable::StartTime(value) => {
19 map.serialize_entry(&"type", &"startTime")?;
20 map.serialize_entry(&"startTime", value)?;
21 }
22 HistogramDistributionVariable::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 HistogramDistributionVariable {
31 fn deserialize<D>(d: D) -> Result<HistogramDistributionVariable, 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 = HistogramDistributionVariable;
41 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
42 fmt.write_str("union HistogramDistributionVariable")
43 }
44 fn visit_map<A>(self, mut map: A) -> Result<HistogramDistributionVariable, 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_::StartTime, Some(Variant_::StartTime)) => {
54 let value = map.next_value()?;
55 HistogramDistributionVariable::StartTime(value)
56 }
57 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
58 if type_ == b {
59 let value = map.next_value()?;
60 HistogramDistributionVariable::Unknown(Unknown {
61 type_,
62 value,
63 })
64 } else {
65 return Err(
66 de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
67 )
68 }
69 }
70 (variant, Some(key)) => {
71 return Err(
72 de::Error::invalid_value(
73 de::Unexpected::Str(key.as_str()),
74 &variant.as_str(),
75 ),
76 );
77 }
78 (variant, None) => {
79 return Err(de::Error::missing_field(variant.as_str()));
80 }
81 }
82 }
83 Some(UnionField_::Value(variant)) => {
84 let value = match &variant {
85 Variant_::StartTime => {
86 let value = map.next_value()?;
87 HistogramDistributionVariable::StartTime(value)
88 }
89 Variant_::Unknown(type_) => {
90 let value = map.next_value()?;
91 HistogramDistributionVariable::Unknown(Unknown {
92 type_: type_.clone(),
93 value,
94 })
95 }
96 };
97 if map.next_key::<UnionTypeField_>()?.is_none() {
98 return Err(de::Error::missing_field("type"));
99 }
100 let type_variant = map.next_value::<Variant_>()?;
101 if variant != type_variant {
102 return Err(
103 de::Error::invalid_value(
104 de::Unexpected::Str(type_variant.as_str()),
105 &variant.as_str(),
106 ),
107 );
108 }
109 value
110 }
111 None => return Err(de::Error::missing_field("type")),
112 };
113 if map.next_key::<UnionField_<Variant_>>()?.is_some() {
114 return Err(de::Error::invalid_length(3, &"type and value fields"));
115 }
116 Ok(v)
117 }
118}
119#[derive(PartialEq)]
120enum Variant_ {
121 StartTime,
122 Unknown(Box<str>),
123}
124impl Variant_ {
125 fn as_str(&self) -> &'static str {
126 match *self {
127 Variant_::StartTime => "startTime",
128 Variant_::Unknown(_) => "unknown variant",
129 }
130 }
131}
132impl<'de> de::Deserialize<'de> for Variant_ {
133 fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
134 where
135 D: de::Deserializer<'de>,
136 {
137 d.deserialize_str(VariantVisitor_)
138 }
139}
140struct VariantVisitor_;
141impl<'de> de::Visitor<'de> for VariantVisitor_ {
142 type Value = Variant_;
143 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
144 fmt.write_str("string")
145 }
146 fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
147 where
148 E: de::Error,
149 {
150 let v = match value {
151 "startTime" => Variant_::StartTime,
152 value => Variant_::Unknown(value.to_string().into_boxed_str()),
153 };
154 Ok(v)
155 }
156}
157#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
159pub struct Unknown {
160 type_: Box<str>,
161 value: conjure_object::Any,
162}
163impl Unknown {
164 #[inline]
166 pub fn type_(&self) -> &str {
167 &self.type_
168 }
169}