163 163 | }
|
164 164 | /// Returns true if this is a [`TimestampValue`](crate::types::MyUnion::TimestampValue).
|
165 165 | pub fn is_timestamp_value(&self) -> bool {
|
166 166 | self.as_timestamp_value().is_ok()
|
167 167 | }
|
168 168 | /// Returns true if the enum instance is the `Unknown` variant.
|
169 169 | pub fn is_unknown(&self) -> bool {
|
170 170 | matches!(self, Self::Unknown)
|
171 171 | }
|
172 172 | }
|
173 + | static MYUNION_SCHEMA_ID: ::aws_smithy_schema::ShapeId =
|
174 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion", "aws.protocoltests.restjson", "MyUnion");
|
175 + | static MYUNION_MEMBER_STRINGVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
176 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$stringValue", "aws.protocoltests.restjson", "MyUnion"),
|
177 + | ::aws_smithy_schema::ShapeType::String,
|
178 + | "stringValue",
|
179 + | 0,
|
180 + | );
|
181 + | static MYUNION_MEMBER_BOOLEANVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
182 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$booleanValue", "aws.protocoltests.restjson", "MyUnion"),
|
183 + | ::aws_smithy_schema::ShapeType::Boolean,
|
184 + | "booleanValue",
|
185 + | 1,
|
186 + | );
|
187 + | static MYUNION_MEMBER_NUMBERVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
188 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$numberValue", "aws.protocoltests.restjson", "MyUnion"),
|
189 + | ::aws_smithy_schema::ShapeType::Integer,
|
190 + | "numberValue",
|
191 + | 2,
|
192 + | );
|
193 + | static MYUNION_MEMBER_BLOBVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
194 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$blobValue", "aws.protocoltests.restjson", "MyUnion"),
|
195 + | ::aws_smithy_schema::ShapeType::Blob,
|
196 + | "blobValue",
|
197 + | 3,
|
198 + | );
|
199 + | static MYUNION_MEMBER_TIMESTAMPVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
200 + | ::aws_smithy_schema::ShapeId::from_static(
|
201 + | "aws.protocoltests.restjson#MyUnion$timestampValue",
|
202 + | "aws.protocoltests.restjson",
|
203 + | "MyUnion",
|
204 + | ),
|
205 + | ::aws_smithy_schema::ShapeType::Timestamp,
|
206 + | "timestampValue",
|
207 + | 4,
|
208 + | );
|
209 + | static MYUNION_MEMBER_ENUMVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
210 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$enumValue", "aws.protocoltests.restjson", "MyUnion"),
|
211 + | ::aws_smithy_schema::ShapeType::String,
|
212 + | "enumValue",
|
213 + | 5,
|
214 + | );
|
215 + | static MYUNION_MEMBER_LISTVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
216 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$listValue", "aws.protocoltests.restjson", "MyUnion"),
|
217 + | ::aws_smithy_schema::ShapeType::List,
|
218 + | "listValue",
|
219 + | 6,
|
220 + | );
|
221 + | static MYUNION_MEMBER_MAPVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
222 + | ::aws_smithy_schema::ShapeId::from_static("aws.protocoltests.restjson#MyUnion$mapValue", "aws.protocoltests.restjson", "MyUnion"),
|
223 + | ::aws_smithy_schema::ShapeType::Map,
|
224 + | "mapValue",
|
225 + | 7,
|
226 + | );
|
227 + | static MYUNION_MEMBER_STRUCTUREVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
228 + | ::aws_smithy_schema::ShapeId::from_static(
|
229 + | "aws.protocoltests.restjson#MyUnion$structureValue",
|
230 + | "aws.protocoltests.restjson",
|
231 + | "MyUnion",
|
232 + | ),
|
233 + | ::aws_smithy_schema::ShapeType::Structure,
|
234 + | "structureValue",
|
235 + | 8,
|
236 + | );
|
237 + | static MYUNION_MEMBER_RENAMEDSTRUCTUREVALUE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
238 + | ::aws_smithy_schema::ShapeId::from_static(
|
239 + | "aws.protocoltests.restjson#MyUnion$renamedStructureValue",
|
240 + | "aws.protocoltests.restjson",
|
241 + | "MyUnion",
|
242 + | ),
|
243 + | ::aws_smithy_schema::ShapeType::Structure,
|
244 + | "renamedStructureValue",
|
245 + | 9,
|
246 + | );
|
247 + | static MYUNION_SCHEMA: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_struct(
|
248 + | MYUNION_SCHEMA_ID,
|
249 + | ::aws_smithy_schema::ShapeType::Union,
|
250 + | &[
|
251 + | &MYUNION_MEMBER_STRINGVALUE,
|
252 + | &MYUNION_MEMBER_BOOLEANVALUE,
|
253 + | &MYUNION_MEMBER_NUMBERVALUE,
|
254 + | &MYUNION_MEMBER_BLOBVALUE,
|
255 + | &MYUNION_MEMBER_TIMESTAMPVALUE,
|
256 + | &MYUNION_MEMBER_ENUMVALUE,
|
257 + | &MYUNION_MEMBER_LISTVALUE,
|
258 + | &MYUNION_MEMBER_MAPVALUE,
|
259 + | &MYUNION_MEMBER_STRUCTUREVALUE,
|
260 + | &MYUNION_MEMBER_RENAMEDSTRUCTUREVALUE,
|
261 + | ],
|
262 + | );
|
263 + | impl MyUnion {
|
264 + | /// The schema for this shape.
|
265 + | pub const SCHEMA: &'static ::aws_smithy_schema::Schema = &MYUNION_SCHEMA;
|
266 + | }
|
267 + | impl ::aws_smithy_schema::serde::SerializableStruct for MyUnion {
|
268 + | #[allow(unused_variables, clippy::diverging_sub_expression)]
|
269 + | fn serialize_members(
|
270 + | &self,
|
271 + | ser: &mut dyn ::aws_smithy_schema::serde::ShapeSerializer,
|
272 + | ) -> ::std::result::Result<(), ::aws_smithy_schema::serde::SerdeError> {
|
273 + | match self {
|
274 + | Self::StringValue(val) => {
|
275 + | ser.write_string(&MYUNION_MEMBER_STRINGVALUE, val)?;
|
276 + | }
|
277 + | Self::BooleanValue(val) => {
|
278 + | ser.write_boolean(&MYUNION_MEMBER_BOOLEANVALUE, *val)?;
|
279 + | }
|
280 + | Self::NumberValue(val) => {
|
281 + | ser.write_integer(&MYUNION_MEMBER_NUMBERVALUE, *val)?;
|
282 + | }
|
283 + | Self::BlobValue(val) => {
|
284 + | ser.write_blob(&MYUNION_MEMBER_BLOBVALUE, val)?;
|
285 + | }
|
286 + | Self::TimestampValue(val) => {
|
287 + | ser.write_timestamp(&MYUNION_MEMBER_TIMESTAMPVALUE, val)?;
|
288 + | }
|
289 + | Self::EnumValue(val) => {
|
290 + | ser.write_string(&MYUNION_MEMBER_ENUMVALUE, val.as_str())?;
|
291 + | }
|
292 + | Self::ListValue(val) => {
|
293 + | ser.write_string_list(&MYUNION_MEMBER_LISTVALUE, val)?;
|
294 + | }
|
295 + | Self::MapValue(val) => {
|
296 + | ser.write_string_string_map(&MYUNION_MEMBER_MAPVALUE, val)?;
|
297 + | }
|
298 + | Self::StructureValue(val) => {
|
299 + | ser.write_struct(&MYUNION_MEMBER_STRUCTUREVALUE, val)?;
|
300 + | }
|
301 + | Self::RenamedStructureValue(val) => {
|
302 + | ser.write_struct(&MYUNION_MEMBER_RENAMEDSTRUCTUREVALUE, val)?;
|
303 + | }
|
304 + | Self::Unknown => return Err(::aws_smithy_schema::serde::SerdeError::custom("cannot serialize unknown union variant")),
|
305 + | }
|
306 + | Ok(())
|
307 + | }
|
308 + | }
|
309 + | impl MyUnion {
|
310 + | /// Deserializes this union from a [`ShapeDeserializer`].
|
311 + | pub fn deserialize(
|
312 + | deserializer: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer,
|
313 + | ) -> ::std::result::Result<Self, ::aws_smithy_schema::serde::SerdeError> {
|
314 + | let mut result: ::std::option::Option<Self> = ::std::option::Option::None;
|
315 + | #[allow(unused_variables, unreachable_code, clippy::single_match, clippy::match_single_binding)]
|
316 + | deserializer.read_struct(&MYUNION_SCHEMA, &mut |member, deser| {
|
317 + | result = ::std::option::Option::Some(match member.member_index() {
|
318 + | Some(0) => Self::StringValue(deser.read_string(member)?),
|
319 + | Some(1) => Self::BooleanValue(deser.read_boolean(member)?),
|
320 + | Some(2) => Self::NumberValue(deser.read_integer(member)?),
|
321 + | Some(3) => Self::BlobValue(deser.read_blob(member)?),
|
322 + | Some(4) => Self::TimestampValue(deser.read_timestamp(member)?),
|
323 + | Some(5) => Self::EnumValue(crate::types::FooEnum::from(deser.read_string(member)?.as_str())),
|
324 + | Some(6) => Self::ListValue(deser.read_string_list(member)?),
|
325 + | Some(7) => Self::MapValue(deser.read_string_string_map(member)?),
|
326 + | Some(8) => Self::StructureValue(crate::types::GreetingStruct::deserialize(deser)?),
|
327 + | Some(9) => Self::RenamedStructureValue(crate::types::RenamedGreeting::deserialize(deser)?),
|
328 + | _ => Self::Unknown,
|
329 + | });
|
330 + | Ok(())
|
331 + | })?;
|
332 + | result.ok_or_else(|| ::aws_smithy_schema::serde::SerdeError::custom("expected a union variant"))
|
333 + | }
|
334 + | }
|