nominal_api/conjure/objects/scout/checks/api/
unresolved_variable_locator.rs1use 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 UnresolvedVariableLocator {
8 ChecklistVariable(super::super::super::compute::api::VariableName),
10 ComputeNode(super::UnresolvedComputeNodeWithContext),
11 Series(super::super::super::api::ChannelLocator),
12 Timestamp(super::TimestampLocator),
13 Unknown(Unknown),
15}
16impl ser::Serialize for UnresolvedVariableLocator {
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 UnresolvedVariableLocator::ChecklistVariable(value) => {
24 map.serialize_entry(&"type", &"checklistVariable")?;
25 map.serialize_entry(&"checklistVariable", value)?;
26 }
27 UnresolvedVariableLocator::ComputeNode(value) => {
28 map.serialize_entry(&"type", &"computeNode")?;
29 map.serialize_entry(&"computeNode", value)?;
30 }
31 UnresolvedVariableLocator::Series(value) => {
32 map.serialize_entry(&"type", &"series")?;
33 map.serialize_entry(&"series", value)?;
34 }
35 UnresolvedVariableLocator::Timestamp(value) => {
36 map.serialize_entry(&"type", &"timestamp")?;
37 map.serialize_entry(&"timestamp", value)?;
38 }
39 UnresolvedVariableLocator::Unknown(value) => {
40 map.serialize_entry(&"type", &value.type_)?;
41 map.serialize_entry(&value.type_, &value.value)?;
42 }
43 }
44 map.end()
45 }
46}
47impl<'de> de::Deserialize<'de> for UnresolvedVariableLocator {
48 fn deserialize<D>(d: D) -> Result<UnresolvedVariableLocator, D::Error>
49 where
50 D: de::Deserializer<'de>,
51 {
52 d.deserialize_map(Visitor_)
53 }
54}
55struct Visitor_;
56impl<'de> de::Visitor<'de> for Visitor_ {
57 type Value = UnresolvedVariableLocator;
58 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
59 fmt.write_str("union UnresolvedVariableLocator")
60 }
61 fn visit_map<A>(self, mut map: A) -> Result<UnresolvedVariableLocator, A::Error>
62 where
63 A: de::MapAccess<'de>,
64 {
65 let v = match map.next_key::<UnionField_<Variant_>>()? {
66 Some(UnionField_::Type) => {
67 let variant = map.next_value()?;
68 let key = map.next_key()?;
69 match (variant, key) {
70 (Variant_::ChecklistVariable, Some(Variant_::ChecklistVariable)) => {
71 let value = map.next_value()?;
72 UnresolvedVariableLocator::ChecklistVariable(value)
73 }
74 (Variant_::ComputeNode, Some(Variant_::ComputeNode)) => {
75 let value = map.next_value()?;
76 UnresolvedVariableLocator::ComputeNode(value)
77 }
78 (Variant_::Series, Some(Variant_::Series)) => {
79 let value = map.next_value()?;
80 UnresolvedVariableLocator::Series(value)
81 }
82 (Variant_::Timestamp, Some(Variant_::Timestamp)) => {
83 let value = map.next_value()?;
84 UnresolvedVariableLocator::Timestamp(value)
85 }
86 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
87 if type_ == b {
88 let value = map.next_value()?;
89 UnresolvedVariableLocator::Unknown(Unknown { type_, value })
90 } else {
91 return Err(
92 de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
93 )
94 }
95 }
96 (variant, Some(key)) => {
97 return Err(
98 de::Error::invalid_value(
99 de::Unexpected::Str(key.as_str()),
100 &variant.as_str(),
101 ),
102 );
103 }
104 (variant, None) => {
105 return Err(de::Error::missing_field(variant.as_str()));
106 }
107 }
108 }
109 Some(UnionField_::Value(variant)) => {
110 let value = match &variant {
111 Variant_::ChecklistVariable => {
112 let value = map.next_value()?;
113 UnresolvedVariableLocator::ChecklistVariable(value)
114 }
115 Variant_::ComputeNode => {
116 let value = map.next_value()?;
117 UnresolvedVariableLocator::ComputeNode(value)
118 }
119 Variant_::Series => {
120 let value = map.next_value()?;
121 UnresolvedVariableLocator::Series(value)
122 }
123 Variant_::Timestamp => {
124 let value = map.next_value()?;
125 UnresolvedVariableLocator::Timestamp(value)
126 }
127 Variant_::Unknown(type_) => {
128 let value = map.next_value()?;
129 UnresolvedVariableLocator::Unknown(Unknown {
130 type_: type_.clone(),
131 value,
132 })
133 }
134 };
135 if map.next_key::<UnionTypeField_>()?.is_none() {
136 return Err(de::Error::missing_field("type"));
137 }
138 let type_variant = map.next_value::<Variant_>()?;
139 if variant != type_variant {
140 return Err(
141 de::Error::invalid_value(
142 de::Unexpected::Str(type_variant.as_str()),
143 &variant.as_str(),
144 ),
145 );
146 }
147 value
148 }
149 None => return Err(de::Error::missing_field("type")),
150 };
151 if map.next_key::<UnionField_<Variant_>>()?.is_some() {
152 return Err(de::Error::invalid_length(3, &"type and value fields"));
153 }
154 Ok(v)
155 }
156}
157#[derive(PartialEq)]
158enum Variant_ {
159 ChecklistVariable,
160 ComputeNode,
161 Series,
162 Timestamp,
163 Unknown(Box<str>),
164}
165impl Variant_ {
166 fn as_str(&self) -> &'static str {
167 match *self {
168 Variant_::ChecklistVariable => "checklistVariable",
169 Variant_::ComputeNode => "computeNode",
170 Variant_::Series => "series",
171 Variant_::Timestamp => "timestamp",
172 Variant_::Unknown(_) => "unknown variant",
173 }
174 }
175}
176impl<'de> de::Deserialize<'de> for Variant_ {
177 fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
178 where
179 D: de::Deserializer<'de>,
180 {
181 d.deserialize_str(VariantVisitor_)
182 }
183}
184struct VariantVisitor_;
185impl<'de> de::Visitor<'de> for VariantVisitor_ {
186 type Value = Variant_;
187 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
188 fmt.write_str("string")
189 }
190 fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
191 where
192 E: de::Error,
193 {
194 let v = match value {
195 "checklistVariable" => Variant_::ChecklistVariable,
196 "computeNode" => Variant_::ComputeNode,
197 "series" => Variant_::Series,
198 "timestamp" => Variant_::Timestamp,
199 value => Variant_::Unknown(value.to_string().into_boxed_str()),
200 };
201 Ok(v)
202 }
203}
204#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
206pub struct Unknown {
207 type_: Box<str>,
208 value: conjure_object::Any,
209}
210impl Unknown {
211 #[inline]
213 pub fn type_(&self) -> &str {
214 &self.type_
215 }
216}