Skip to main content

nominal_api/conjure/objects/scout/compute/api/
numeric_resample_interpolation_configuration.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, conjure_object::private::DeriveWith)]
6#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub enum NumericResampleInterpolationConfiguration {
8    ForwardFillResampleInterpolationConfiguration(
9        super::ForwardFillResampleInterpolationConfiguration,
10    ),
11    ConstantResampleInterpolationConfiguration(
12        super::NumericConstantResampleInterpolationConfiguration,
13    ),
14    /// An unknown variant.
15    Unknown(Unknown),
16}
17impl ser::Serialize for NumericResampleInterpolationConfiguration {
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            NumericResampleInterpolationConfiguration::ForwardFillResampleInterpolationConfiguration(
25                value,
26            ) => {
27                map.serialize_entry(
28                    &"type",
29                    &"forwardFillResampleInterpolationConfiguration",
30                )?;
31                map.serialize_entry(
32                    &"forwardFillResampleInterpolationConfiguration",
33                    value,
34                )?;
35            }
36            NumericResampleInterpolationConfiguration::ConstantResampleInterpolationConfiguration(
37                value,
38            ) => {
39                map.serialize_entry(
40                    &"type",
41                    &"constantResampleInterpolationConfiguration",
42                )?;
43                map.serialize_entry(
44                    &"constantResampleInterpolationConfiguration",
45                    value,
46                )?;
47            }
48            NumericResampleInterpolationConfiguration::Unknown(value) => {
49                map.serialize_entry(&"type", &value.type_)?;
50                map.serialize_entry(&value.type_, &value.value)?;
51            }
52        }
53        map.end()
54    }
55}
56impl<'de> de::Deserialize<'de> for NumericResampleInterpolationConfiguration {
57    fn deserialize<D>(
58        d: D,
59    ) -> Result<NumericResampleInterpolationConfiguration, D::Error>
60    where
61        D: de::Deserializer<'de>,
62    {
63        d.deserialize_map(Visitor_)
64    }
65}
66struct Visitor_;
67impl<'de> de::Visitor<'de> for Visitor_ {
68    type Value = NumericResampleInterpolationConfiguration;
69    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
70        fmt.write_str("union NumericResampleInterpolationConfiguration")
71    }
72    fn visit_map<A>(
73        self,
74        mut map: A,
75    ) -> Result<NumericResampleInterpolationConfiguration, A::Error>
76    where
77        A: de::MapAccess<'de>,
78    {
79        let v = match map.next_key::<UnionField_<Variant_>>()? {
80            Some(UnionField_::Type) => {
81                let variant = map.next_value()?;
82                let key = map.next_key()?;
83                match (variant, key) {
84                    (
85                        Variant_::ForwardFillResampleInterpolationConfiguration,
86                        Some(Variant_::ForwardFillResampleInterpolationConfiguration),
87                    ) => {
88                        let value = map.next_value()?;
89                        NumericResampleInterpolationConfiguration::ForwardFillResampleInterpolationConfiguration(
90                            value,
91                        )
92                    }
93                    (
94                        Variant_::ConstantResampleInterpolationConfiguration,
95                        Some(Variant_::ConstantResampleInterpolationConfiguration),
96                    ) => {
97                        let value = map.next_value()?;
98                        NumericResampleInterpolationConfiguration::ConstantResampleInterpolationConfiguration(
99                            value,
100                        )
101                    }
102                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
103                        if type_ == b {
104                            let value = map.next_value()?;
105                            NumericResampleInterpolationConfiguration::Unknown(Unknown {
106                                type_,
107                                value,
108                            })
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_::ForwardFillResampleInterpolationConfiguration => {
131                        let value = map.next_value()?;
132                        NumericResampleInterpolationConfiguration::ForwardFillResampleInterpolationConfiguration(
133                            value,
134                        )
135                    }
136                    Variant_::ConstantResampleInterpolationConfiguration => {
137                        let value = map.next_value()?;
138                        NumericResampleInterpolationConfiguration::ConstantResampleInterpolationConfiguration(
139                            value,
140                        )
141                    }
142                    Variant_::Unknown(type_) => {
143                        let value = map.next_value()?;
144                        NumericResampleInterpolationConfiguration::Unknown(Unknown {
145                            type_: type_.clone(),
146                            value,
147                        })
148                    }
149                };
150                if map.next_key::<UnionTypeField_>()?.is_none() {
151                    return Err(de::Error::missing_field("type"));
152                }
153                let type_variant = map.next_value::<Variant_>()?;
154                if variant != type_variant {
155                    return Err(
156                        de::Error::invalid_value(
157                            de::Unexpected::Str(type_variant.as_str()),
158                            &variant.as_str(),
159                        ),
160                    );
161                }
162                value
163            }
164            None => return Err(de::Error::missing_field("type")),
165        };
166        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
167            return Err(de::Error::invalid_length(3, &"type and value fields"));
168        }
169        Ok(v)
170    }
171}
172#[derive(PartialEq)]
173enum Variant_ {
174    ForwardFillResampleInterpolationConfiguration,
175    ConstantResampleInterpolationConfiguration,
176    Unknown(Box<str>),
177}
178impl Variant_ {
179    fn as_str(&self) -> &'static str {
180        match *self {
181            Variant_::ForwardFillResampleInterpolationConfiguration => {
182                "forwardFillResampleInterpolationConfiguration"
183            }
184            Variant_::ConstantResampleInterpolationConfiguration => {
185                "constantResampleInterpolationConfiguration"
186            }
187            Variant_::Unknown(_) => "unknown variant",
188        }
189    }
190}
191impl<'de> de::Deserialize<'de> for Variant_ {
192    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
193    where
194        D: de::Deserializer<'de>,
195    {
196        d.deserialize_str(VariantVisitor_)
197    }
198}
199struct VariantVisitor_;
200impl<'de> de::Visitor<'de> for VariantVisitor_ {
201    type Value = Variant_;
202    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
203        fmt.write_str("string")
204    }
205    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
206    where
207        E: de::Error,
208    {
209        let v = match value {
210            "forwardFillResampleInterpolationConfiguration" => {
211                Variant_::ForwardFillResampleInterpolationConfiguration
212            }
213            "constantResampleInterpolationConfiguration" => {
214                Variant_::ConstantResampleInterpolationConfiguration
215            }
216            value => Variant_::Unknown(value.to_string().into_boxed_str()),
217        };
218        Ok(v)
219    }
220}
221///An unknown variant of the NumericResampleInterpolationConfiguration union.
222#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
223pub struct Unknown {
224    type_: Box<str>,
225    value: conjure_object::Any,
226}
227impl Unknown {
228    /// Returns the unknown variant's type name.
229    #[inline]
230    pub fn type_(&self) -> &str {
231        &self.type_
232    }
233}