aws-sdk-payments 1.1.0

AWS SDK for AWS Payments
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub(crate) fn de_payment_instrument_details<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
    _value: &'a [u8],
    depth: u32,
) -> ::std::result::Result<Option<crate::types::PaymentInstrumentDetails>, ::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",
        ));
    }
    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() {
                        "card" => Some(crate::types::PaymentInstrumentDetails::Card(
                            crate::protocol_serde::shape_card::de_card(tokens, _value, depth + 1)?
                                .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'card' cannot be null"))?,
                        )),
                        "usAchBankAccount" => Some(crate::types::PaymentInstrumentDetails::UsAchBankAccount(
                            crate::protocol_serde::shape_us_ach_bank_account::de_us_ach_bank_account(tokens, _value, depth + 1)?.ok_or_else(
                                || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'usAchBankAccount' cannot be null"),
                            )?,
                        )),
                        "sepaBankAccount" => Some(crate::types::PaymentInstrumentDetails::SepaBankAccount(
                            crate::protocol_serde::shape_sepa_bank_account::de_sepa_bank_account(tokens, _value, depth + 1)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'sepaBankAccount' cannot be null")
                            })?,
                        )),
                        "ukBacsBankAccount" => Some(crate::types::PaymentInstrumentDetails::UkBacsBankAccount(
                            crate::protocol_serde::shape_uk_bacs_bank_account::de_uk_bacs_bank_account(tokens, _value, depth + 1)?.ok_or_else(
                                || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'ukBacsBankAccount' cannot be null"),
                            )?,
                        )),
                        "inNetBanking" => Some(crate::types::PaymentInstrumentDetails::InNetBanking(
                            crate::protocol_serde::shape_in_net_banking::de_in_net_banking(tokens, _value, depth + 1)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'inNetBanking' cannot be null")
                            })?,
                        )),
                        "cnBankRedirect" => Some(crate::types::PaymentInstrumentDetails::CnBankRedirect(
                            crate::protocol_serde::shape_cn_bank_redirect::de_cn_bank_redirect(tokens, _value, depth + 1)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'cnBankRedirect' cannot be null")
                            })?,
                        )),
                        "upi" => Some(crate::types::PaymentInstrumentDetails::Upi(
                            crate::protocol_serde::shape_upi::de_upi(tokens, _value, depth + 1)?
                                .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'upi' cannot be null"))?,
                        )),
                        _ => {
                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                            Some(crate::types::PaymentInstrumentDetails::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)
}