aws_sdk_s3/protocol_serde/
shape_cors_rule.rs#[allow(clippy::needless_question_mark)]
pub fn de_cors_rule(
decoder: &mut ::aws_smithy_xml::decode::ScopedDecoder,
) -> Result<crate::types::CorsRule, ::aws_smithy_xml::decode::XmlDecodeError> {
#[allow(unused_mut)]
let mut builder = crate::types::CorsRule::builder();
while let Some(mut tag) = decoder.next_tag() {
match tag.start_el() {
s if s.matches("ID") => {
let var_1 =
Some(
Result::<::std::string::String, ::aws_smithy_xml::decode::XmlDecodeError>::Ok(
::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
.into()
)
?
)
;
builder = builder.set_id(var_1);
}
,
s if s.matches("AllowedHeader") => {
let var_2 =
Some(
Result::<::std::vec::Vec::<::std::string::String>, ::aws_smithy_xml::decode::XmlDecodeError>::Ok({
let mut list_3 = builder.allowed_headers.take().unwrap_or_default();
list_3.push(
Result::<::std::string::String, ::aws_smithy_xml::decode::XmlDecodeError>::Ok(
::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
.into()
)
?
);
list_3
})
?
)
;
builder = builder.set_allowed_headers(var_2);
}
,
s if s.matches("AllowedMethod") => {
let var_4 =
Some(
Result::<::std::vec::Vec::<::std::string::String>, ::aws_smithy_xml::decode::XmlDecodeError>::Ok({
let mut list_5 = builder.allowed_methods.take().unwrap_or_default();
list_5.push(
Result::<::std::string::String, ::aws_smithy_xml::decode::XmlDecodeError>::Ok(
::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
.into()
)
?
);
list_5
})
?
)
;
builder = builder.set_allowed_methods(var_4);
}
,
s if s.matches("AllowedOrigin") => {
let var_6 =
Some(
Result::<::std::vec::Vec::<::std::string::String>, ::aws_smithy_xml::decode::XmlDecodeError>::Ok({
let mut list_7 = builder.allowed_origins.take().unwrap_or_default();
list_7.push(
Result::<::std::string::String, ::aws_smithy_xml::decode::XmlDecodeError>::Ok(
::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
.into()
)
?
);
list_7
})
?
)
;
builder = builder.set_allowed_origins(var_6);
}
,
s if s.matches("ExposeHeader") => {
let var_8 =
Some(
Result::<::std::vec::Vec::<::std::string::String>, ::aws_smithy_xml::decode::XmlDecodeError>::Ok({
let mut list_9 = builder.expose_headers.take().unwrap_or_default();
list_9.push(
Result::<::std::string::String, ::aws_smithy_xml::decode::XmlDecodeError>::Ok(
::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
.into()
)
?
);
list_9
})
?
)
;
builder = builder.set_expose_headers(var_8);
}
,
s if s.matches("MaxAgeSeconds") => {
let var_10 =
Some(
{
<i32 as ::aws_smithy_types::primitive::Parse>::parse_smithy_primitive(
::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
)
.map_err(|_|::aws_smithy_xml::decode::XmlDecodeError::custom("expected (integer: `com.amazonaws.s3#MaxAgeSeconds`)"))
}
?
)
;
builder = builder.set_max_age_seconds(var_10);
}
,
_ => {}
}
}
Ok(crate::serde_util::cors_rule_correct_errors(builder)
.build()
.map_err(|_| ::aws_smithy_xml::decode::XmlDecodeError::custom("missing field"))?)
}
pub fn ser_cors_rule(
input: &crate::types::CorsRule,
writer: ::aws_smithy_xml::encode::ElWriter,
) -> Result<(), ::aws_smithy_types::error::operation::SerializationError> {
#[allow(unused_mut)]
let mut scope = writer.finish();
if let Some(var_11) = &input.id {
let mut inner_writer = scope.start_el("ID").finish();
inner_writer.data(var_11.as_str());
}
if let Some(var_12) = &input.allowed_headers {
for list_item_13 in var_12 {
{
let mut inner_writer = scope.start_el("AllowedHeader").finish();
inner_writer.data(list_item_13.as_str());
}
}
}
{
for list_item_14 in &input.allowed_methods {
{
let mut inner_writer = scope.start_el("AllowedMethod").finish();
inner_writer.data(list_item_14.as_str());
}
}
}
{
for list_item_15 in &input.allowed_origins {
{
let mut inner_writer = scope.start_el("AllowedOrigin").finish();
inner_writer.data(list_item_15.as_str());
}
}
}
if let Some(var_16) = &input.expose_headers {
for list_item_17 in var_16 {
{
let mut inner_writer = scope.start_el("ExposeHeader").finish();
inner_writer.data(list_item_17.as_str());
}
}
}
if let Some(var_18) = &input.max_age_seconds {
let mut inner_writer = scope.start_el("MaxAgeSeconds").finish();
inner_writer.data(::aws_smithy_types::primitive::Encoder::from(*var_18).encode());
}
scope.finish();
Ok(())
}