aws_sdk_accessanalyzer/protocol_serde/
shape_rds_db_snapshot_attribute_value.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_rds_db_snapshot_attribute_value(
3    object_5: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::RdsDbSnapshotAttributeValue,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    match input {
7        crate::types::RdsDbSnapshotAttributeValue::AccountIds(inner) => {
8            let mut array_1 = object_5.key("accountIds").start_array();
9            for item_2 in inner {
10                {
11                    array_1.value().string(item_2.as_str());
12                }
13            }
14            array_1.finish();
15        }
16        crate::types::RdsDbSnapshotAttributeValue::Unknown => {
17            return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
18                "RdsDbSnapshotAttributeValue",
19            ))
20        }
21    }
22    Ok(())
23}
24
25pub(crate) fn de_rds_db_snapshot_attribute_value<'a, I>(
26    tokens: &mut ::std::iter::Peekable<I>,
27) -> ::std::result::Result<Option<crate::types::RdsDbSnapshotAttributeValue>, ::aws_smithy_json::deserialize::error::DeserializeError>
28where
29    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
30{
31    let mut variant = None;
32    match tokens.next().transpose()? {
33        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
34        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
35            match tokens.next().transpose()? {
36                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
37                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
38                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
39                        tokens.peek()
40                    {
41                        let _ = tokens.next().expect("peek returned a token")?;
42                        continue;
43                    }
44                    let key = key.to_unescaped()?;
45                    if key == "__type" {
46                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
47                        continue;
48                    }
49                    if variant.is_some() {
50                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
51                            "encountered mixed variants in union",
52                        ));
53                    }
54                    variant = match key.as_ref() {
55                        "accountIds" => Some(crate::types::RdsDbSnapshotAttributeValue::AccountIds(
56                            crate::protocol_serde::shape_rds_db_snapshot_account_ids_list::de_rds_db_snapshot_account_ids_list(tokens)?.ok_or_else(
57                                || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'accountIds' cannot be null"),
58                            )?,
59                        )),
60                        _ => {
61                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
62                            Some(crate::types::RdsDbSnapshotAttributeValue::Unknown)
63                        }
64                    };
65                }
66                other => {
67                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
68                        "expected object key or end object, found: {:?}",
69                        other
70                    )))
71                }
72            }
73        },
74        _ => {
75            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
76                "expected start object or null",
77            ))
78        }
79    }
80    if variant.is_none() {
81        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
82            "Union did not contain a valid variant.",
83        ));
84    }
85    Ok(variant)
86}