Skip to main content

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