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