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_synthesize_speech_http_response(
    response: &mut ::aws_smithy_runtime_api::http::Response,
) -> std::result::Result<crate::operation::synthesize_speech::SynthesizeSpeechOutput, crate::operation::synthesize_speech::SynthesizeSpeechError> {
    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::synthesize_speech::builders::SynthesizeSpeechOutputBuilder::default();
        output = output.set_audio_stream(Some(crate::protocol_serde::shape_synthesize_speech_output::de_audio_stream_payload(
            _response_body,
        )?));
        output = output.set_content_type(
            crate::protocol_serde::shape_synthesize_speech_output::de_content_type_header(_response_headers).map_err(|_| {
                crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled("Failed to parse ContentType from header `Content-Type")
            })?,
        );
        output = output.set_request_characters(
            crate::protocol_serde::shape_synthesize_speech_output::de_request_characters_header(_response_headers).map_err(|_| {
                crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled(
                    "Failed to parse RequestCharacters from header `x-amzn-RequestCharacters",
                )
            })?,
        );
        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
        output.build()
    })
}

#[allow(clippy::unnecessary_wraps)]
pub fn de_synthesize_speech_http_error(
    _response_status: u16,
    _response_headers: &::aws_smithy_runtime_api::http::Headers,
    _response_body: &[u8],
) -> std::result::Result<crate::operation::synthesize_speech::SynthesizeSpeechOutput, crate::operation::synthesize_speech::SynthesizeSpeechError> {
    #[allow(unused_mut)]
    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
        .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::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::synthesize_speech::SynthesizeSpeechError::unhandled(generic)),
    };

    let _error_message = generic.message().map(|msg| msg.to_owned());
    Err(match error_code {
        "EngineNotSupportedException" => crate::operation::synthesize_speech::SynthesizeSpeechError::EngineNotSupportedException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::EngineNotSupportedExceptionBuilder::default();
                output =
                    crate::protocol_serde::shape_engine_not_supported_exception::de_engine_not_supported_exception_json_err(_response_body, output)
                        .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "InvalidSampleRateException" => crate::operation::synthesize_speech::SynthesizeSpeechError::InvalidSampleRateException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::InvalidSampleRateExceptionBuilder::default();
                output =
                    crate::protocol_serde::shape_invalid_sample_rate_exception::de_invalid_sample_rate_exception_json_err(_response_body, output)
                        .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "InvalidSsmlException" => crate::operation::synthesize_speech::SynthesizeSpeechError::InvalidSsmlException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::InvalidSsmlExceptionBuilder::default();
                output = crate::protocol_serde::shape_invalid_ssml_exception::de_invalid_ssml_exception_json_err(_response_body, output)
                    .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "LanguageNotSupportedException" => crate::operation::synthesize_speech::SynthesizeSpeechError::LanguageNotSupportedException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::LanguageNotSupportedExceptionBuilder::default();
                output = crate::protocol_serde::shape_language_not_supported_exception::de_language_not_supported_exception_json_err(
                    _response_body,
                    output,
                )
                .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "LexiconNotFoundException" => crate::operation::synthesize_speech::SynthesizeSpeechError::LexiconNotFoundException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::LexiconNotFoundExceptionBuilder::default();
                output = crate::protocol_serde::shape_lexicon_not_found_exception::de_lexicon_not_found_exception_json_err(_response_body, output)
                    .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "MarksNotSupportedForFormatException" => crate::operation::synthesize_speech::SynthesizeSpeechError::MarksNotSupportedForFormatException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::MarksNotSupportedForFormatExceptionBuilder::default();
                output = crate::protocol_serde::shape_marks_not_supported_for_format_exception::de_marks_not_supported_for_format_exception_json_err(
                    _response_body,
                    output,
                )
                .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ServiceFailureException" => crate::operation::synthesize_speech::SynthesizeSpeechError::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::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "SsmlMarksNotSupportedForTextTypeException" => {
            crate::operation::synthesize_speech::SynthesizeSpeechError::SsmlMarksNotSupportedForTextTypeException({
                #[allow(unused_mut)]
                let mut tmp = {
                    #[allow(unused_mut)]
                    let mut output = crate::types::error::builders::SsmlMarksNotSupportedForTextTypeExceptionBuilder::default();
                    output = crate::protocol_serde::shape_ssml_marks_not_supported_for_text_type_exception::de_ssml_marks_not_supported_for_text_type_exception_json_err(_response_body, output).map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                    let output = output.meta(generic);
                    output.build()
                };
                if tmp.message.is_none() {
                    tmp.message = _error_message;
                }
                tmp
            })
        }
        "TextLengthExceededException" => crate::operation::synthesize_speech::SynthesizeSpeechError::TextLengthExceededException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::TextLengthExceededExceptionBuilder::default();
                output =
                    crate::protocol_serde::shape_text_length_exceeded_exception::de_text_length_exceeded_exception_json_err(_response_body, output)
                        .map_err(crate::operation::synthesize_speech::SynthesizeSpeechError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        _ => crate::operation::synthesize_speech::SynthesizeSpeechError::generic(generic),
    })
}

pub fn ser_synthesize_speech_input(
    input: &crate::operation::synthesize_speech::SynthesizeSpeechInput,
) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
    let mut out = String::new();
    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
    crate::protocol_serde::shape_synthesize_speech_input::ser_synthesize_speech_input_input(&mut object, input)?;
    object.finish();
    Ok(::aws_smithy_types::body::SdkBody::from(out))
}