aws-sdk-applicationautoscaling 1.112.0

AWS SDK for Application Auto Scaling
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_predictive_scaling_policy_configuration(
    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::PredictiveScalingPolicyConfiguration,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    {
        let mut array_1 = object.key("MetricSpecifications").start_array();
        for item_2 in &input.metric_specifications {
            {
                #[allow(unused_mut)]
                let mut object_3 = array_1.value().start_object();
                crate::protocol_serde::shape_predictive_scaling_metric_specification::ser_predictive_scaling_metric_specification(
                    &mut object_3,
                    item_2,
                )?;
                object_3.finish();
            }
        }
        array_1.finish();
    }
    if let Some(var_4) = &input.mode {
        object.key("Mode").string(var_4.as_str());
    }
    if let Some(var_5) = &input.scheduling_buffer_time {
        object.key("SchedulingBufferTime").number(
            #[allow(clippy::useless_conversion)]
            ::aws_smithy_types::Number::NegInt((*var_5).into()),
        );
    }
    if let Some(var_6) = &input.max_capacity_breach_behavior {
        object.key("MaxCapacityBreachBehavior").string(var_6.as_str());
    }
    if let Some(var_7) = &input.max_capacity_buffer {
        object.key("MaxCapacityBuffer").number(
            #[allow(clippy::useless_conversion)]
            ::aws_smithy_types::Number::NegInt((*var_7).into()),
        );
    }
    Ok(())
}

pub(crate) fn de_predictive_scaling_policy_configuration<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
    _value: &'a [u8],
    depth: u32,
) -> ::std::result::Result<Option<crate::types::PredictiveScalingPolicyConfiguration>, ::aws_smithy_json::deserialize::error::DeserializeError>
where
    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
{
    if depth >= 128u32 {
        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "maximum nesting depth exceeded",
        ));
    }
    match tokens.next().transpose()? {
        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
            #[allow(unused_mut)]
            let mut builder = crate::types::builders::PredictiveScalingPolicyConfigurationBuilder::default();
            loop {
                match tokens.next().transpose()? {
                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
                        match key.to_unescaped()?.as_ref() {
                            "MetricSpecifications" => {
                                builder = builder.set_metric_specifications(
                                    crate::protocol_serde::shape_predictive_scaling_metric_specifications::de_predictive_scaling_metric_specifications(tokens, _value, depth + 1)?
                                );
                            }
                            "Mode" => {
                                builder = builder.set_mode(
                                    ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                        .map(|s| s.to_unescaped().map(|u| crate::types::PredictiveScalingMode::from(u.as_ref())))
                                        .transpose()?,
                                );
                            }
                            "SchedulingBufferTime" => {
                                builder = builder.set_scheduling_buffer_time(
                                    ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
                                        .map(i32::try_from)
                                        .transpose()?,
                                );
                            }
                            "MaxCapacityBreachBehavior" => {
                                builder = builder.set_max_capacity_breach_behavior(
                                    ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                        .map(|s| {
                                            s.to_unescaped()
                                                .map(|u| crate::types::PredictiveScalingMaxCapacityBreachBehavior::from(u.as_ref()))
                                        })
                                        .transpose()?,
                                );
                            }
                            "MaxCapacityBuffer" => {
                                builder = builder.set_max_capacity_buffer(
                                    ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
                                        .map(i32::try_from)
                                        .transpose()?,
                                );
                            }
                            _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
                        }
                    }
                    other => {
                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
                            "expected object key or end object, found: {other:?}"
                        )))
                    }
                }
            }
            Ok(Some(
                crate::serde_util::predictive_scaling_policy_configuration_correct_errors(builder)
                    .build()
                    .map_err(|err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err))?,
            ))
        }
        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "expected start object or null",
        )),
    }
}