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