Skip to main content

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