aws_sdk_sagemaker/protocol_serde/
shape_scaling_policy.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_scaling_policy<'a, I>(
3    tokens: &mut ::std::iter::Peekable<I>,
4) -> ::std::result::Result<Option<crate::types::ScalingPolicy>, ::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                            "TargetTracking" => {
33                                Some(crate::types::ScalingPolicy::TargetTracking(
34                                    crate::protocol_serde::shape_target_tracking_scaling_policy_configuration::de_target_tracking_scaling_policy_configuration(tokens)?
35                                    .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'TargetTracking' cannot be null"))?
36                                ))
37                            }
38                            _ => {
39                                                                              ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
40                                                                              Some(crate::types::ScalingPolicy::Unknown)
41                                                                            }
42                        };
43                }
44                other => {
45                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
46                        "expected object key or end object, found: {:?}",
47                        other
48                    )))
49                }
50            }
51        },
52        _ => {
53            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
54                "expected start object or null",
55            ))
56        }
57    }
58    if variant.is_none() {
59        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
60            "Union did not contain a valid variant.",
61        ));
62    }
63    Ok(variant)
64}