aws_sdk_backup/protocol_serde/
shape_date_range.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_date_range<'a, I>(
3    tokens: &mut ::std::iter::Peekable<I>,
4) -> ::std::result::Result<Option<crate::types::DateRange>, ::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    match tokens.next().transpose()? {
9        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
10        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
11            #[allow(unused_mut)]
12            let mut builder = crate::types::builders::DateRangeBuilder::default();
13            loop {
14                match tokens.next().transpose()? {
15                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
16                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
17                        "FromDate" => {
18                            builder = builder.set_from_date(::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
19                                tokens.next(),
20                                ::aws_smithy_types::date_time::Format::EpochSeconds,
21                            )?);
22                        }
23                        "ToDate" => {
24                            builder = builder.set_to_date(::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
25                                tokens.next(),
26                                ::aws_smithy_types::date_time::Format::EpochSeconds,
27                            )?);
28                        }
29                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
30                    },
31                    other => {
32                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
33                            "expected object key or end object, found: {:?}",
34                            other
35                        )))
36                    }
37                }
38            }
39            Ok(Some(crate::serde_util::date_range_correct_errors(builder).build().map_err(|err| {
40                ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err)
41            })?))
42        }
43        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
44            "expected start object or null",
45        )),
46    }
47}
48
49pub fn ser_date_range(
50    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
51    input: &crate::types::DateRange,
52) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
53    {
54        object
55            .key("FromDate")
56            .date_time(&input.from_date, ::aws_smithy_types::date_time::Format::EpochSeconds)?;
57    }
58    {
59        object
60            .key("ToDate")
61            .date_time(&input.to_date, ::aws_smithy_types::date_time::Format::EpochSeconds)?;
62    }
63    Ok(())
64}