aws_sdk_sagemaker/protocol_serde/
shape_event_metadata.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_event_metadata<'a, I>(
3    tokens: &mut ::std::iter::Peekable<I>,
4) -> ::std::result::Result<Option<crate::types::EventMetadata>, ::aws_smithy_json::deserialize::error::DeserializeError>
5where
6    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
7{
8    let mut variant = None;
9    match tokens.next().transpose()? {
10        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
11        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
12            match tokens.next().transpose()? {
13                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
14                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
15                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
16                        tokens.peek()
17                    {
18                        let _ = tokens.next().expect("peek returned a token")?;
19                        continue;
20                    }
21                    let key = key.to_unescaped()?;
22                    if key == "__type" {
23                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
24                        continue;
25                    }
26                    if variant.is_some() {
27                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
28                            "encountered mixed variants in union",
29                        ));
30                    }
31                    variant = match key.as_ref() {
32                        "Cluster" => Some(crate::types::EventMetadata::Cluster(
33                            crate::protocol_serde::shape_cluster_metadata::de_cluster_metadata(tokens)?.ok_or_else(|| {
34                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Cluster' cannot be null")
35                            })?,
36                        )),
37                        "InstanceGroup" => Some(crate::types::EventMetadata::InstanceGroup(
38                            crate::protocol_serde::shape_instance_group_metadata::de_instance_group_metadata(tokens)?.ok_or_else(|| {
39                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'InstanceGroup' cannot be null")
40                            })?,
41                        )),
42                        "InstanceGroupScaling" => Some(crate::types::EventMetadata::InstanceGroupScaling(
43                            crate::protocol_serde::shape_instance_group_scaling_metadata::de_instance_group_scaling_metadata(tokens)?.ok_or_else(
44                                || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'InstanceGroupScaling' cannot be null"),
45                            )?,
46                        )),
47                        "Instance" => Some(crate::types::EventMetadata::Instance(
48                            crate::protocol_serde::shape_instance_metadata::de_instance_metadata(tokens)?.ok_or_else(|| {
49                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Instance' cannot be null")
50                            })?,
51                        )),
52                        _ => {
53                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
54                            Some(crate::types::EventMetadata::Unknown)
55                        }
56                    };
57                }
58                other => {
59                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
60                        "expected object key or end object, found: {:?}",
61                        other
62                    )))
63                }
64            }
65        },
66        _ => {
67            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
68                "expected start object or null",
69            ))
70        }
71    }
72    if variant.is_none() {
73        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
74            "Union did not contain a valid variant.",
75        ));
76    }
77    Ok(variant)
78}