aws-sdk-greengrass 0.26.0

AWS SDK for AWS Greengrass
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_function_configuration(
    object: &mut aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::FunctionConfiguration,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
    if let Some(var_1) = &input.encoding_type {
        object.key("EncodingType").string(var_1.as_str());
    }
    if let Some(var_2) = &input.environment {
        #[allow(unused_mut)]
        let mut object_3 = object.key("Environment").start_object();
        crate::protocol_serde::shape_function_configuration_environment::ser_function_configuration_environment(&mut object_3, var_2)?;
        object_3.finish();
    }
    if let Some(var_4) = &input.exec_args {
        object.key("ExecArgs").string(var_4.as_str());
    }
    if let Some(var_5) = &input.executable {
        object.key("Executable").string(var_5.as_str());
    }
    if input.memory_size != 0 {
        object.key("MemorySize").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((input.memory_size).into()),
        );
    }
    if input.pinned {
        object.key("Pinned").boolean(input.pinned);
    }
    if input.timeout != 0 {
        object.key("Timeout").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((input.timeout).into()),
        );
    }
    if let Some(var_6) = &input.function_runtime_override {
        object.key("FunctionRuntimeOverride").string(var_6.as_str());
    }
    Ok(())
}

pub(crate) fn de_function_configuration<'a, I>(
    tokens: &mut std::iter::Peekable<I>,
) -> Result<
    Option<crate::types::FunctionConfiguration>,
    aws_smithy_json::deserialize::error::DeserializeError,
>
where
    I: Iterator<
        Item = Result<
            aws_smithy_json::deserialize::Token<'a>,
            aws_smithy_json::deserialize::error::DeserializeError,
        >,
    >,
{
    match tokens.next().transpose()? {
        Some(aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
        Some(aws_smithy_json::deserialize::Token::StartObject { .. }) => {
            #[allow(unused_mut)]
            let mut builder = crate::types::builders::FunctionConfigurationBuilder::default();
            loop {
                match tokens.next().transpose()? {
                    Some(aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
                    Some(aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
                        match key.to_unescaped()?.as_ref() {
                            "EncodingType" => {
                                builder = builder.set_encoding_type(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| {
                                        s.to_unescaped()
                                            .map(|u| crate::types::EncodingType::from(u.as_ref()))
                                    })
                                    .transpose()?,
                                );
                            }
                            "Environment" => {
                                builder = builder.set_environment(
                                    crate::protocol_serde::shape_function_configuration_environment::de_function_configuration_environment(tokens)?
                                );
                            }
                            "ExecArgs" => {
                                builder = builder.set_exec_args(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "Executable" => {
                                builder = builder.set_executable(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "MemorySize" => {
                                builder = builder.set_memory_size(
                                    aws_smithy_json::deserialize::token::expect_number_or_null(
                                        tokens.next(),
                                    )?
                                    .map(i32::try_from)
                                    .transpose()?,
                                );
                            }
                            "Pinned" => {
                                builder = builder.set_pinned(
                                    aws_smithy_json::deserialize::token::expect_bool_or_null(
                                        tokens.next(),
                                    )?,
                                );
                            }
                            "Timeout" => {
                                builder = builder.set_timeout(
                                    aws_smithy_json::deserialize::token::expect_number_or_null(
                                        tokens.next(),
                                    )?
                                    .map(i32::try_from)
                                    .transpose()?,
                                );
                            }
                            "FunctionRuntimeOverride" => {
                                builder = builder.set_function_runtime_override(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            _ => aws_smithy_json::deserialize::token::skip_value(tokens)?,
                        }
                    }
                    other => {
                        return Err(
                            aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
                                "expected object key or end object, found: {:?}",
                                other
                            )),
                        )
                    }
                }
            }
            Ok(Some(builder.build()))
        }
        _ => Err(
            aws_smithy_json::deserialize::error::DeserializeError::custom(
                "expected start object or null",
            ),
        ),
    }
}