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