Skip to main content

aws_sdk_budgets/protocol_serde/
shape_historical_options.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_historical_options(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::HistoricalOptions,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object.key("BudgetAdjustmentPeriod").number(
8            #[allow(clippy::useless_conversion)]
9            ::aws_smithy_types::Number::NegInt((input.budget_adjustment_period).into()),
10        );
11    }
12    if let Some(var_1) = &input.look_back_available_periods {
13        object.key("LookBackAvailablePeriods").number(
14            #[allow(clippy::useless_conversion)]
15            ::aws_smithy_types::Number::NegInt((*var_1).into()),
16        );
17    }
18    Ok(())
19}
20
21pub(crate) fn de_historical_options<'a, I>(
22    tokens: &mut ::std::iter::Peekable<I>,
23    _value: &'a [u8],
24) -> ::std::result::Result<Option<crate::types::HistoricalOptions>, ::aws_smithy_json::deserialize::error::DeserializeError>
25where
26    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
27{
28    match tokens.next().transpose()? {
29        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
30        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
31            #[allow(unused_mut)]
32            let mut builder = crate::types::builders::HistoricalOptionsBuilder::default();
33            loop {
34                match tokens.next().transpose()? {
35                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
36                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
37                        "BudgetAdjustmentPeriod" => {
38                            builder = builder.set_budget_adjustment_period(
39                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
40                                    .map(i32::try_from)
41                                    .transpose()?,
42                            );
43                        }
44                        "LookBackAvailablePeriods" => {
45                            builder = builder.set_look_back_available_periods(
46                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
47                                    .map(i32::try_from)
48                                    .transpose()?,
49                            );
50                        }
51                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
52                    },
53                    other => {
54                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
55                            "expected object key or end object, found: {other:?}"
56                        )))
57                    }
58                }
59            }
60            Ok(Some(crate::serde_util::historical_options_correct_errors(builder).build().map_err(
61                |err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err),
62            )?))
63        }
64        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
65            "expected start object or null",
66        )),
67    }
68}