Unverified Commit 8b386a88 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

No more unpin (#248)

* Remove unecessary Unpin bound

* Cargo Fmt
parent 6b38bf71
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ impl<S, O, T, E, B, R> tower::Service<operation::Operation<O, R>> for ParseRespo
where
    S: Service<operation::Request, Response = http::Response<B>, Error = SendOperationError>,
    S::Future: 'static,
    B: http_body::Body + Unpin + 'static,
    B: http_body::Body + 'static,
    B::Error: Into<BoxError>,
    O: ParseHttpResponse<B, Output = Result<T, E>> + 'static,
    E: Error,
+15 −8
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use crate::pin_mut;
use crate::response::ParseHttpResponse;
use crate::result::{SdkError, SdkSuccess};
use bytes::{Buf, Bytes};
use http::Response;
use http_body::Body;
use std::error::Error;

@@ -39,7 +40,7 @@ impl ResponseBody {
    pub fn bytes(&self) -> Option<&[u8]> {
        match &self.0 {
            Inner::Bytes(bytes) => Some(&bytes),
            _ => None
            _ => None,
        }
    }
}
@@ -52,7 +53,6 @@ enum Inner {
    Err,
}


type BoxError = Box<dyn Error + Send + Sync>;

/// [`MapRequest`] defines a synchronous middleware that transforms an [`operation::Request`].
@@ -111,27 +111,34 @@ pub async fn load_response<B, T, E, O>(
    handler: &O,
) -> Result<SdkSuccess<T>, SdkError<E>>
where
    B: http_body::Body + Unpin,
    B: http_body::Body,
    B::Error: Into<BoxError>,
    O: ParseHttpResponse<B, Output = Result<T, E>>,
{
    if let Some(parsed_response) = handler.parse_unloaded(&mut response) {
        return sdk_result(parsed_response, response.map(|_|ResponseBody(Inner::Streaming)));
        return sdk_result(
            parsed_response,
            response.map(|_| ResponseBody(Inner::Streaming)),
        );
    }
    let (parts, body) = response.into_parts();

    let body = match read_body(response.body_mut()).await {
    let body = match read_body(body).await {
        Ok(body) => body,
        Err(e) => {
            return Err(SdkError::ResponseError {
                raw: response.map(|_|ResponseBody(Inner::Err)),
                raw: Response::from_parts(parts, ResponseBody(Inner::Err)),
                err: e.into(),
            });
        }
    };

    let response = response.map(|_| Bytes::from(body));
    let response = Response::from_parts(parts, Bytes::from(body));
    let parsed = handler.parse_loaded(&response);
    sdk_result(parsed, response.map(|body|ResponseBody(Inner::Bytes(body))))
    sdk_result(
        parsed,
        response.map(|body| ResponseBody(Inner::Bytes(body))),
    )
}

async fn read_body<B: http_body::Body>(body: B) -> Result<Vec<u8>, B::Error> {
+5 −2
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use crate::middleware::ResponseBody;
use std::error::Error;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};
use crate::middleware::ResponseBody;

type BoxError = Box<dyn Error + Send + Sync>;
/// Successful Sdk Result
@@ -34,7 +34,10 @@ pub enum SdkError<E> {
    },

    /// An error response was received from the service
    ServiceError { err: E, raw: http::Response<ResponseBody> },
    ServiceError {
        err: E,
        raw: http::Response<ResponseBody>,
    },
}

impl<E> Display for SdkError<E>