aws-sdk-connect 1.183.0

AWS SDK for Amazon Connect Service
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_evaluation_form_section(
    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::EvaluationFormSection,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    {
        object.key("Title").string(input.title.as_str());
    }
    {
        object.key("RefId").string(input.ref_id.as_str());
    }
    if let Some(var_1) = &input.instructions {
        object.key("Instructions").string(var_1.as_str());
    }
    {
        let mut array_2 = object.key("Items").start_array();
        for item_3 in &input.items {
            {
                #[allow(unused_mut)]
                let mut object_4 = array_2.value().start_object();
                crate::protocol_serde::shape_evaluation_form_item::ser_evaluation_form_item(&mut object_4, item_3)?;
                object_4.finish();
            }
        }
        array_2.finish();
    }
    if input.weight != 0.0 {
        object.key("Weight").number(
            #[allow(clippy::useless_conversion)]
            ::aws_smithy_types::Number::Float((input.weight).into()),
        );
    }
    if input.is_excluded_from_scoring {
        object.key("IsExcludedFromScoring").boolean(input.is_excluded_from_scoring);
    }
    if let Some(var_5) = &input.score_thresholds {
        let mut array_6 = object.key("ScoreThresholds").start_array();
        for item_7 in var_5 {
            {
                #[allow(unused_mut)]
                let mut object_8 = array_6.value().start_object();
                crate::protocol_serde::shape_evaluation_form_score_threshold::ser_evaluation_form_score_threshold(&mut object_8, item_7)?;
                object_8.finish();
            }
        }
        array_6.finish();
    }
    Ok(())
}

pub(crate) fn de_evaluation_form_section<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
    _value: &'a [u8],
    depth: u32,
) -> ::std::result::Result<Option<crate::types::EvaluationFormSection>, ::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::EvaluationFormSectionBuilder::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() {
                        "Title" => {
                            builder = builder.set_title(
                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                            );
                        }
                        "RefId" => {
                            builder = builder.set_ref_id(
                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                            );
                        }
                        "Instructions" => {
                            builder = builder.set_instructions(
                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                            );
                        }
                        "Items" => {
                            builder = builder.set_items(crate::protocol_serde::shape_evaluation_form_items_list::de_evaluation_form_items_list(
                                tokens,
                                _value,
                                depth + 1,
                            )?);
                        }
                        "Weight" => {
                            builder = builder
                                .set_weight(::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?.map(|v| v.to_f64_lossy()));
                        }
                        "IsExcludedFromScoring" => {
                            builder =
                                builder.set_is_excluded_from_scoring(::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?);
                        }
                        "ScoreThresholds" => {
                            builder = builder.set_score_thresholds(
                                crate::protocol_serde::shape_evaluation_form_score_threshold_list::de_evaluation_form_score_threshold_list(
                                    tokens,
                                    _value,
                                    depth + 1,
                                )?,
                            );
                        }
                        _ => ::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::evaluation_form_section_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",
        )),
    }
}