Skip to main content

aws_sdk_accessanalyzer/protocol_serde/
shape_path_element.rs

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