aws_sdk_wisdom/protocol_serde/
shape_quick_response_content_provider.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_quick_response_content_provider<'a, I>(
3    tokens: &mut ::std::iter::Peekable<I>,
4) -> ::std::result::Result<Option<crate::types::QuickResponseContentProvider>, ::aws_smithy_json::deserialize::error::DeserializeError>
5where
6    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
7{
8    let mut variant = None;
9    match tokens.next().transpose()? {
10        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
11        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
12            match tokens.next().transpose()? {
13                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
14                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
15                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
16                        tokens.peek()
17                    {
18                        let _ = tokens.next().expect("peek returned a token")?;
19                        continue;
20                    }
21                    let key = key.to_unescaped()?;
22                    if key == "__type" {
23                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
24                        continue;
25                    }
26                    if variant.is_some() {
27                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
28                            "encountered mixed variants in union",
29                        ));
30                    }
31                    variant = match key.as_ref() {
32                        "content" => Some(crate::types::QuickResponseContentProvider::Content(
33                            ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
34                                .map(|s| s.to_unescaped().map(|u| u.into_owned()))
35                                .transpose()?
36                                .ok_or_else(|| {
37                                    ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'content' cannot be null")
38                                })?,
39                        )),
40                        _ => {
41                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
42                            Some(crate::types::QuickResponseContentProvider::Unknown)
43                        }
44                    };
45                }
46                other => {
47                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
48                        "expected object key or end object, found: {other:?}"
49                    )))
50                }
51            }
52        },
53        _ => {
54            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
55                "expected start object or null",
56            ))
57        }
58    }
59    if variant.is_none() {
60        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
61            "Union did not contain a valid variant.",
62        ));
63    }
64    Ok(variant)
65}