aws-sdk-connect 1.153.0

AWS SDK for Amazon Connect Service
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub(crate) fn de_reference_summary<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
) -> ::std::result::Result<Option<crate::types::ReferenceSummary>, ::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() {
                        "Url" => Some(crate::types::ReferenceSummary::Url(
                            crate::protocol_serde::shape_url_reference::de_url_reference(tokens)?
                                .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Url' cannot be null"))?,
                        )),
                        "Attachment" => Some(crate::types::ReferenceSummary::Attachment(
                            crate::protocol_serde::shape_attachment_reference::de_attachment_reference(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Attachment' cannot be null")
                            })?,
                        )),
                        "EmailMessage" => Some(crate::types::ReferenceSummary::EmailMessage(
                            crate::protocol_serde::shape_email_message_reference::de_email_message_reference(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'EmailMessage' cannot be null")
                            })?,
                        )),
                        "EmailMessagePlainText" => Some(crate::types::ReferenceSummary::EmailMessagePlainText(
                            crate::protocol_serde::shape_email_message_reference::de_email_message_reference(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'EmailMessagePlainText' cannot be null")
                            })?,
                        )),
                        "String" => Some(crate::types::ReferenceSummary::String(
                            crate::protocol_serde::shape_string_reference::de_string_reference(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'String' cannot be null")
                            })?,
                        )),
                        "Number" => Some(crate::types::ReferenceSummary::Number(
                            crate::protocol_serde::shape_number_reference::de_number_reference(tokens)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Number' cannot be null")
                            })?,
                        )),
                        "Date" => Some(crate::types::ReferenceSummary::Date(
                            crate::protocol_serde::shape_date_reference::de_date_reference(tokens)?
                                .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Date' cannot be null"))?,
                        )),
                        "Email" => Some(crate::types::ReferenceSummary::Email(
                            crate::protocol_serde::shape_email_reference::de_email_reference(tokens)?
                                .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Email' cannot be null"))?,
                        )),
                        _ => {
                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                            Some(crate::types::ReferenceSummary::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)
}