aws-sdk-bedrockagent 1.96.0

AWS SDK for Agents for Amazon Bedrock
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_reranking_metadata_selective_mode_configuration(
    object_2: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::RerankingMetadataSelectiveModeConfiguration,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    match input {
        crate::types::RerankingMetadataSelectiveModeConfiguration::FieldsToInclude(inner) => {
            let mut array_1 = object_2.key("fieldsToInclude").start_array();
            for item_2 in inner {
                {
                    #[allow(unused_mut)]
                    let mut object_3 = array_1.value().start_object();
                    crate::protocol_serde::shape_field_for_reranking::ser_field_for_reranking(&mut object_3, item_2)?;
                    object_3.finish();
                }
            }
            array_1.finish();
        }
        crate::types::RerankingMetadataSelectiveModeConfiguration::FieldsToExclude(inner) => {
            let mut array_4 = object_2.key("fieldsToExclude").start_array();
            for item_5 in inner {
                {
                    #[allow(unused_mut)]
                    let mut object_6 = array_4.value().start_object();
                    crate::protocol_serde::shape_field_for_reranking::ser_field_for_reranking(&mut object_6, item_5)?;
                    object_6.finish();
                }
            }
            array_4.finish();
        }
        crate::types::RerankingMetadataSelectiveModeConfiguration::Unknown => {
            return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
                "RerankingMetadataSelectiveModeConfiguration",
            ))
        }
    }
    Ok(())
}

pub(crate) fn de_reranking_metadata_selective_mode_configuration<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
) -> ::std::result::Result<Option<crate::types::RerankingMetadataSelectiveModeConfiguration>, ::aws_smithy_json::deserialize::error::DeserializeError>
where
    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
{
    let mut variant = None;
    match tokens.next().transpose()? {
        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
            match tokens.next().transpose()? {
                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
                        tokens.peek()
                    {
                        let _ = tokens.next().expect("peek returned a token")?;
                        continue;
                    }
                    let key = key.to_unescaped()?;
                    if key == "__type" {
                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                        continue;
                    }
                    if variant.is_some() {
                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
                            "encountered mixed variants in union",
                        ));
                    }
                    variant = match key.as_ref() {
                        "fieldsToInclude" => Some(crate::types::RerankingMetadataSelectiveModeConfiguration::FieldsToInclude(
                            crate::protocol_serde::shape_fields_for_reranking::de_fields_for_reranking(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'fieldsToInclude' cannot be null")
                            })?,
                        )),
                        "fieldsToExclude" => Some(crate::types::RerankingMetadataSelectiveModeConfiguration::FieldsToExclude(
                            crate::protocol_serde::shape_fields_for_reranking::de_fields_for_reranking(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'fieldsToExclude' cannot be null")
                            })?,
                        )),
                        _ => {
                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                            Some(crate::types::RerankingMetadataSelectiveModeConfiguration::Unknown)
                        }
                    };
                }
                other => {
                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
                        "expected object key or end object, found: {:?}",
                        other
                    )))
                }
            }
        },
        _ => {
            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
                "expected start object or null",
            ))
        }
    }
    if variant.is_none() {
        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "Union did not contain a valid variant.",
        ));
    }
    Ok(variant)
}