Skip to main content

nominal_api/conjure/objects/scout/compute/resolved/api/
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 ResampleInterpolationConfiguration {
8    ForwardFillResampleInterpolationConfiguration(
9        super::ForwardFillResampleInterpolationConfiguration,
10    ),
11    ConstantDefaultValueResampleInterpolationConfiguration(
12        super::ConstantDefaultValueResampleInterpolationConfiguration,
13    ),
14    /// An unknown variant.
15    Unknown(Unknown),
16}
17impl ser::Serialize for ResampleInterpolationConfiguration {
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            ResampleInterpolationConfiguration::ForwardFillResampleInterpolationConfiguration(
25                value,
26            ) => {
27                map.serialize_entry(
28                    &"type",
29                    &"forwardFillResampleInterpolationConfiguration",
30                )?;
31                map.serialize_entry(
32                    &"forwardFillResampleInterpolationConfiguration",
33                    value,
34                )?;
35            }
36            ResampleInterpolationConfiguration::ConstantDefaultValueResampleInterpolationConfiguration(
37                value,
38            ) => {
39                map.serialize_entry(
40                    &"type",
41                    &"constantDefaultValueResampleInterpolationConfiguration",
42                )?;
43                map.serialize_entry(
44                    &"constantDefaultValueResampleInterpolationConfiguration",
45                    value,
46                )?;
47            }
48            ResampleInterpolationConfiguration::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 ResampleInterpolationConfiguration {
57    fn deserialize<D>(d: D) -> Result<ResampleInterpolationConfiguration, D::Error>
58    where
59        D: de::Deserializer<'de>,
60    {
61        d.deserialize_map(Visitor_)
62    }
63}
64struct Visitor_;
65impl<'de> de::Visitor<'de> for Visitor_ {
66    type Value = ResampleInterpolationConfiguration;
67    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
68        fmt.write_str("union ResampleInterpolationConfiguration")
69    }
70    fn visit_map<A>(
71        self,
72        mut map: A,
73    ) -> Result<ResampleInterpolationConfiguration, A::Error>
74    where
75        A: de::MapAccess<'de>,
76    {
77        let v = match map.next_key::<UnionField_<Variant_>>()? {
78            Some(UnionField_::Type) => {
79                let variant = map.next_value()?;
80                let key = map.next_key()?;
81                match (variant, key) {
82                    (
83                        Variant_::ForwardFillResampleInterpolationConfiguration,
84                        Some(Variant_::ForwardFillResampleInterpolationConfiguration),
85                    ) => {
86                        let value = map.next_value()?;
87                        ResampleInterpolationConfiguration::ForwardFillResampleInterpolationConfiguration(
88                            value,
89                        )
90                    }
91                    (
92                        Variant_::ConstantDefaultValueResampleInterpolationConfiguration,
93                        Some(
94                            Variant_::ConstantDefaultValueResampleInterpolationConfiguration,
95                        ),
96                    ) => {
97                        let value = map.next_value()?;
98                        ResampleInterpolationConfiguration::ConstantDefaultValueResampleInterpolationConfiguration(
99                            value,
100                        )
101                    }
102                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
103                        if type_ == b {
104                            let value = map.next_value()?;
105                            ResampleInterpolationConfiguration::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                        ResampleInterpolationConfiguration::ForwardFillResampleInterpolationConfiguration(
133                            value,
134                        )
135                    }
136                    Variant_::ConstantDefaultValueResampleInterpolationConfiguration => {
137                        let value = map.next_value()?;
138                        ResampleInterpolationConfiguration::ConstantDefaultValueResampleInterpolationConfiguration(
139                            value,
140                        )
141                    }
142                    Variant_::Unknown(type_) => {
143                        let value = map.next_value()?;
144                        ResampleInterpolationConfiguration::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    ConstantDefaultValueResampleInterpolationConfiguration,
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_::ConstantDefaultValueResampleInterpolationConfiguration => {
185                "constantDefaultValueResampleInterpolationConfiguration"
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            "constantDefaultValueResampleInterpolationConfiguration" => {
214                Variant_::ConstantDefaultValueResampleInterpolationConfiguration
215            }
216            value => Variant_::Unknown(value.to_string().into_boxed_str()),
217        };
218        Ok(v)
219    }
220}
221///An unknown variant of the ResampleInterpolationConfiguration 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}