aws_sdk_pinpoint/protocol_serde/
shape_segments_response.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_segments_response_payload(
3    input: &[u8],
4) -> ::std::result::Result<crate::types::SegmentsResponse, ::aws_smithy_json::deserialize::error::DeserializeError> {
5    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(input)).peekable();
6    let tokens = &mut tokens_owned;
7    let result = crate::protocol_serde::shape_segments_response::de_segments_response(tokens)?
8        .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("expected payload member value"));
9    if tokens.next().is_some() {
10        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
11            "found more JSON tokens after completing parsing",
12        ));
13    }
14    result
15}
16
17pub(crate) fn de_segments_response<'a, I>(
18    tokens: &mut ::std::iter::Peekable<I>,
19) -> ::std::result::Result<Option<crate::types::SegmentsResponse>, ::aws_smithy_json::deserialize::error::DeserializeError>
20where
21    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
22{
23    match tokens.next().transpose()? {
24        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
25        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
26            #[allow(unused_mut)]
27            let mut builder = crate::types::builders::SegmentsResponseBuilder::default();
28            loop {
29                match tokens.next().transpose()? {
30                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
31                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
32                        "Item" => {
33                            builder = builder.set_item(crate::protocol_serde::shape_list_of_segment_response::de_list_of_segment_response(
34                                tokens,
35                            )?);
36                        }
37                        "NextToken" => {
38                            builder = builder.set_next_token(
39                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
40                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
41                                    .transpose()?,
42                            );
43                        }
44                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
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            Ok(Some(crate::serde_util::segments_response_correct_errors(builder).build()))
54        }
55        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
56            "expected start object or null",
57        )),
58    }
59}