nominal_api/conjure/objects/scout/savedviews/api/
search_saved_views_query.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 SearchSavedViewsQuery {
7 And(super::SearchSavedViewsQueryList),
8 Or(super::SearchSavedViewsQueryList),
9 Not(Box<super::SearchSavedViewsQuery>),
10 TitleExactSubstringSearch(String),
11 ResourceType(super::ResourceType),
12 Workspace(super::super::super::super::api::rids::WorkspaceRid),
13 Unknown(Unknown),
15}
16impl ser::Serialize for SearchSavedViewsQuery {
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 SearchSavedViewsQuery::And(value) => {
24 map.serialize_entry(&"type", &"and")?;
25 map.serialize_entry(&"and", value)?;
26 }
27 SearchSavedViewsQuery::Or(value) => {
28 map.serialize_entry(&"type", &"or")?;
29 map.serialize_entry(&"or", value)?;
30 }
31 SearchSavedViewsQuery::Not(value) => {
32 map.serialize_entry(&"type", &"not")?;
33 map.serialize_entry(&"not", value)?;
34 }
35 SearchSavedViewsQuery::TitleExactSubstringSearch(value) => {
36 map.serialize_entry(&"type", &"titleExactSubstringSearch")?;
37 map.serialize_entry(&"titleExactSubstringSearch", value)?;
38 }
39 SearchSavedViewsQuery::ResourceType(value) => {
40 map.serialize_entry(&"type", &"resourceType")?;
41 map.serialize_entry(&"resourceType", value)?;
42 }
43 SearchSavedViewsQuery::Workspace(value) => {
44 map.serialize_entry(&"type", &"workspace")?;
45 map.serialize_entry(&"workspace", value)?;
46 }
47 SearchSavedViewsQuery::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 SearchSavedViewsQuery {
56 fn deserialize<D>(d: D) -> Result<SearchSavedViewsQuery, 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 = SearchSavedViewsQuery;
66 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
67 fmt.write_str("union SearchSavedViewsQuery")
68 }
69 fn visit_map<A>(self, mut map: A) -> Result<SearchSavedViewsQuery, 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_::And, Some(Variant_::And)) => {
79 let value = map.next_value()?;
80 SearchSavedViewsQuery::And(value)
81 }
82 (Variant_::Or, Some(Variant_::Or)) => {
83 let value = map.next_value()?;
84 SearchSavedViewsQuery::Or(value)
85 }
86 (Variant_::Not, Some(Variant_::Not)) => {
87 let value = map.next_value()?;
88 SearchSavedViewsQuery::Not(value)
89 }
90 (
91 Variant_::TitleExactSubstringSearch,
92 Some(Variant_::TitleExactSubstringSearch),
93 ) => {
94 let value = map.next_value()?;
95 SearchSavedViewsQuery::TitleExactSubstringSearch(value)
96 }
97 (Variant_::ResourceType, Some(Variant_::ResourceType)) => {
98 let value = map.next_value()?;
99 SearchSavedViewsQuery::ResourceType(value)
100 }
101 (Variant_::Workspace, Some(Variant_::Workspace)) => {
102 let value = map.next_value()?;
103 SearchSavedViewsQuery::Workspace(value)
104 }
105 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
106 if type_ == b {
107 let value = map.next_value()?;
108 SearchSavedViewsQuery::Unknown(Unknown { type_, value })
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_::And => {
131 let value = map.next_value()?;
132 SearchSavedViewsQuery::And(value)
133 }
134 Variant_::Or => {
135 let value = map.next_value()?;
136 SearchSavedViewsQuery::Or(value)
137 }
138 Variant_::Not => {
139 let value = map.next_value()?;
140 SearchSavedViewsQuery::Not(value)
141 }
142 Variant_::TitleExactSubstringSearch => {
143 let value = map.next_value()?;
144 SearchSavedViewsQuery::TitleExactSubstringSearch(value)
145 }
146 Variant_::ResourceType => {
147 let value = map.next_value()?;
148 SearchSavedViewsQuery::ResourceType(value)
149 }
150 Variant_::Workspace => {
151 let value = map.next_value()?;
152 SearchSavedViewsQuery::Workspace(value)
153 }
154 Variant_::Unknown(type_) => {
155 let value = map.next_value()?;
156 SearchSavedViewsQuery::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 And,
187 Or,
188 Not,
189 TitleExactSubstringSearch,
190 ResourceType,
191 Workspace,
192 Unknown(Box<str>),
193}
194impl Variant_ {
195 fn as_str(&self) -> &'static str {
196 match *self {
197 Variant_::And => "and",
198 Variant_::Or => "or",
199 Variant_::Not => "not",
200 Variant_::TitleExactSubstringSearch => "titleExactSubstringSearch",
201 Variant_::ResourceType => "resourceType",
202 Variant_::Workspace => "workspace",
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 "and" => Variant_::And,
227 "or" => Variant_::Or,
228 "not" => Variant_::Not,
229 "titleExactSubstringSearch" => Variant_::TitleExactSubstringSearch,
230 "resourceType" => Variant_::ResourceType,
231 "workspace" => Variant_::Workspace,
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}