Skip to main content

nominal_api/conjure/objects/scout/compute/api/
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, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum InterpolationConfiguration {
7    ForwardFillInterpolation(super::ForwardFillInterpolation),
8    /// An unknown variant.
9    Unknown(Unknown),
10}
11impl ser::Serialize for InterpolationConfiguration {
12    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
13    where
14        S: ser::Serializer,
15    {
16        let mut map = s.serialize_map(Some(2))?;
17        match self {
18            InterpolationConfiguration::ForwardFillInterpolation(value) => {
19                map.serialize_entry(&"type", &"forwardFillInterpolation")?;
20                map.serialize_entry(&"forwardFillInterpolation", value)?;
21            }
22            InterpolationConfiguration::Unknown(value) => {
23                map.serialize_entry(&"type", &value.type_)?;
24                map.serialize_entry(&value.type_, &value.value)?;
25            }
26        }
27        map.end()
28    }
29}
30impl<'de> de::Deserialize<'de> for InterpolationConfiguration {
31    fn deserialize<D>(d: D) -> Result<InterpolationConfiguration, D::Error>
32    where
33        D: de::Deserializer<'de>,
34    {
35        d.deserialize_map(Visitor_)
36    }
37}
38struct Visitor_;
39impl<'de> de::Visitor<'de> for Visitor_ {
40    type Value = InterpolationConfiguration;
41    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
42        fmt.write_str("union InterpolationConfiguration")
43    }
44    fn visit_map<A>(self, mut map: A) -> Result<InterpolationConfiguration, A::Error>
45    where
46        A: de::MapAccess<'de>,
47    {
48        let v = match map.next_key::<UnionField_<Variant_>>()? {
49            Some(UnionField_::Type) => {
50                let variant = map.next_value()?;
51                let key = map.next_key()?;
52                match (variant, key) {
53                    (
54                        Variant_::ForwardFillInterpolation,
55                        Some(Variant_::ForwardFillInterpolation),
56                    ) => {
57                        let value = map.next_value()?;
58                        InterpolationConfiguration::ForwardFillInterpolation(value)
59                    }
60                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
61                        if type_ == b {
62                            let value = map.next_value()?;
63                            InterpolationConfiguration::Unknown(Unknown { type_, value })
64                        } else {
65                            return Err(
66                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
67                            )
68                        }
69                    }
70                    (variant, Some(key)) => {
71                        return Err(
72                            de::Error::invalid_value(
73                                de::Unexpected::Str(key.as_str()),
74                                &variant.as_str(),
75                            ),
76                        );
77                    }
78                    (variant, None) => {
79                        return Err(de::Error::missing_field(variant.as_str()));
80                    }
81                }
82            }
83            Some(UnionField_::Value(variant)) => {
84                let value = match &variant {
85                    Variant_::ForwardFillInterpolation => {
86                        let value = map.next_value()?;
87                        InterpolationConfiguration::ForwardFillInterpolation(value)
88                    }
89                    Variant_::Unknown(type_) => {
90                        let value = map.next_value()?;
91                        InterpolationConfiguration::Unknown(Unknown {
92                            type_: type_.clone(),
93                            value,
94                        })
95                    }
96                };
97                if map.next_key::<UnionTypeField_>()?.is_none() {
98                    return Err(de::Error::missing_field("type"));
99                }
100                let type_variant = map.next_value::<Variant_>()?;
101                if variant != type_variant {
102                    return Err(
103                        de::Error::invalid_value(
104                            de::Unexpected::Str(type_variant.as_str()),
105                            &variant.as_str(),
106                        ),
107                    );
108                }
109                value
110            }
111            None => return Err(de::Error::missing_field("type")),
112        };
113        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
114            return Err(de::Error::invalid_length(3, &"type and value fields"));
115        }
116        Ok(v)
117    }
118}
119#[derive(PartialEq)]
120enum Variant_ {
121    ForwardFillInterpolation,
122    Unknown(Box<str>),
123}
124impl Variant_ {
125    fn as_str(&self) -> &'static str {
126        match *self {
127            Variant_::ForwardFillInterpolation => "forwardFillInterpolation",
128            Variant_::Unknown(_) => "unknown variant",
129        }
130    }
131}
132impl<'de> de::Deserialize<'de> for Variant_ {
133    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
134    where
135        D: de::Deserializer<'de>,
136    {
137        d.deserialize_str(VariantVisitor_)
138    }
139}
140struct VariantVisitor_;
141impl<'de> de::Visitor<'de> for VariantVisitor_ {
142    type Value = Variant_;
143    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
144        fmt.write_str("string")
145    }
146    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
147    where
148        E: de::Error,
149    {
150        let v = match value {
151            "forwardFillInterpolation" => Variant_::ForwardFillInterpolation,
152            value => Variant_::Unknown(value.to_string().into_boxed_str()),
153        };
154        Ok(v)
155    }
156}
157///An unknown variant of the InterpolationConfiguration union.
158#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
159pub struct Unknown {
160    type_: Box<str>,
161    value: conjure_object::Any,
162}
163impl Unknown {
164    /// Returns the unknown variant's type name.
165    #[inline]
166    pub fn type_(&self) -> &str {
167        &self.type_
168    }
169}