Skip to main content

nominal_api/conjure/objects/module/
search_modules_query.rs

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