aws-sdk-polly 1.109.0

AWS SDK for Amazon Polly
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
#[allow(clippy::unnecessary_wraps)]
pub fn de_start_speech_synthesis_stream_http_response(
    response: &mut ::aws_smithy_runtime_api::http::Response,
) -> std::result::Result<
    crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamOutput,
    crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError,
> {
    let mut _response_body = ::aws_smithy_types::body::SdkBody::taken();
    std::mem::swap(&mut _response_body, response.body_mut());
    let _response_body = &mut _response_body;

    let _response_status = response.status().as_u16();
    let _response_headers = response.headers();
    Ok({
        #[allow(unused_mut)]
        let mut output = crate::operation::start_speech_synthesis_stream::builders::StartSpeechSynthesisStreamOutputBuilder::default();
        output = output.set_event_stream(Some(
            crate::protocol_serde::shape_start_speech_synthesis_stream_output::de_event_stream_payload(_response_body)?,
        ));
        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
        output
            .build()
            .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?
    })
}

#[allow(clippy::unnecessary_wraps)]
pub fn de_start_speech_synthesis_stream_http_error(
    _response_status: u16,
    _response_headers: &::aws_smithy_runtime_api::http::Headers,
    _response_body: &[u8],
) -> std::result::Result<
    crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamOutput,
    crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError,
> {
    #[allow(unused_mut)]
    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
        .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?;
    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
    let generic = generic_builder.build();
    let error_code = match generic.code() {
        Some(code) => code,
        None => return Err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled(generic)),
    };

    let _error_message = generic.message().map(|msg| msg.to_owned());
    Err(match error_code {
        "ServiceFailureException" => crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::ServiceFailureException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ServiceFailureExceptionBuilder::default();
                output = crate::protocol_serde::shape_service_failure_exception::de_service_failure_exception_json_err(_response_body, output)
                    .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ServiceQuotaExceededException" => {
            crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::ServiceQuotaExceededException({
                #[allow(unused_mut)]
                let mut tmp = {
                    #[allow(unused_mut)]
                    let mut output = crate::types::error::builders::ServiceQuotaExceededExceptionBuilder::default();
                    output = crate::protocol_serde::shape_service_quota_exceeded_exception::de_service_quota_exceeded_exception_json_err(
                        _response_body,
                        output,
                    )
                    .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?;
                    let output = output.meta(generic);
                    crate::serde_util::service_quota_exceeded_exception_correct_errors(output)
                        .build()
                        .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?
                };
                tmp
            })
        }
        "ThrottlingException" => crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::ThrottlingException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
                    .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ValidationException" => crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::ValidationException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ValidationExceptionBuilder::default();
                output = crate::protocol_serde::shape_validation_exception::de_validation_exception_json_err(_response_body, output)
                    .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?;
                let output = output.meta(generic);
                crate::serde_util::validation_exception_correct_errors(output)
                    .build()
                    .map_err(crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::unhandled)?
            };
            tmp
        }),
        _ => crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamError::generic(generic),
    })
}

pub fn ser_start_speech_synthesis_stream_headers(
    input: &crate::operation::start_speech_synthesis_stream::StartSpeechSynthesisStreamInput,
    mut builder: ::http_1x::request::Builder,
) -> std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
    if let ::std::option::Option::Some(inner_1) = &input.engine {
        let formatted_2 = inner_1.as_str();
        let header_value = formatted_2;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "engine",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("x-amzn-Engine", header_value);
    }
    if let ::std::option::Option::Some(inner_3) = &input.language_code {
        let formatted_4 = inner_3.as_str();
        let header_value = formatted_4;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "language_code",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("x-amzn-LanguageCode", header_value);
    }
    if let ::std::option::Option::Some(inner_5) = &input.lexicon_names {
        // Empty vec in header is serialized as an empty string
        if inner_5.is_empty() {
            builder = builder.header("x-amzn-LexiconNames", "");
        } else {
            for inner_6 in inner_5 {
                let formatted_7 = ::aws_smithy_http::header::quote_header_value(inner_6.as_str());
                let header_value = formatted_7;
                let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
                    ::aws_smithy_types::error::operation::BuildError::invalid_field(
                        "lexicon_names",
                        format!("`{}` cannot be used as a header value: {}", &header_value, err),
                    )
                })?;
                builder = builder.header("x-amzn-LexiconNames", header_value);
            }
        }
    }
    if let ::std::option::Option::Some(inner_8) = &input.output_format {
        let formatted_9 = inner_8.as_str();
        let header_value = formatted_9;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "output_format",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("x-amzn-OutputFormat", header_value);
    }
    if let ::std::option::Option::Some(inner_10) = &input.sample_rate {
        let formatted_11 = inner_10.as_str();
        let header_value = formatted_11;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "sample_rate",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("x-amzn-SampleRate", header_value);
    }
    if let ::std::option::Option::Some(inner_12) = &input.voice_id {
        let formatted_13 = inner_12.as_str();
        let header_value = formatted_13;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "voice_id",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("x-amzn-VoiceId", header_value);
    }
    Ok(builder)
}