use crate::erase::DynConnector;
use crate::http_connector::HttpConnector;
use crate::*;
use aws_smithy_http::result::ConnectorError;
pub type Parsed<S, O, Retry> =
aws_smithy_http_tower::parse_response::ParseResponseService<S, O, Retry>;
pub trait SmithyConnector:
Service<
http::Request<SdkBody>,
Response = http::Response<SdkBody>,
Error = <Self as SmithyConnector>::Error,
Future = <Self as SmithyConnector>::Future,
> + Send
+ Sync
+ Clone
+ 'static
{
type Error: Into<ConnectorError> + Send + Sync + 'static;
type Future: Send + 'static;
}
impl<T> SmithyConnector for T
where
T: Service<http::Request<SdkBody>, Response = http::Response<SdkBody>>
+ Send
+ Sync
+ Clone
+ 'static,
T::Error: Into<ConnectorError> + Send + Sync + 'static,
T::Future: Send + 'static,
{
type Error = T::Error;
type Future = T::Future;
}
impl<T, E, F> From<T> for HttpConnector
where
E: Into<ConnectorError> + Send + Sync + 'static,
F: Send + 'static,
T: SmithyConnector<Error = E, Future = F, Response = http::Response<SdkBody>>,
{
fn from(smithy_connector: T) -> Self {
HttpConnector::Prebuilt(Some(DynConnector::new(smithy_connector)))
}
}
pub trait SmithyMiddlewareService:
Service<
aws_smithy_http::operation::Request,
Response = aws_smithy_http::operation::Response,
Error = aws_smithy_http_tower::SendOperationError,
Future = <Self as SmithyMiddlewareService>::Future,
>
{
type Future: Send + 'static;
}
impl<T> SmithyMiddlewareService for T
where
T: Service<
aws_smithy_http::operation::Request,
Response = aws_smithy_http::operation::Response,
Error = aws_smithy_http_tower::SendOperationError,
>,
T::Future: Send + 'static,
{
type Future = T::Future;
}
pub trait SmithyMiddleware<C>:
Layer<
aws_smithy_http_tower::dispatch::DispatchService<C>,
Service = <Self as SmithyMiddleware<C>>::Service,
>
{
type Service: SmithyMiddlewareService + Send + Sync + Clone + 'static;
}
impl<T, C> SmithyMiddleware<C> for T
where
T: Layer<aws_smithy_http_tower::dispatch::DispatchService<C>>,
T::Service: SmithyMiddlewareService + Send + Sync + Clone + 'static,
{
type Service = T::Service;
}
pub trait SmithyRetryPolicy<O, T, E, Retry>:
tower::retry::Policy<Operation<O, Retry>, SdkSuccess<T>, SdkError<E>> + Clone
{
type O: ParseHttpResponse<Output = Result<T, Self::E>> + Send + Sync + Clone + 'static;
type E: Error;
type Retry: ClassifyRetry<SdkSuccess<T>, SdkError<Self::E>>;
}
impl<R, O, T, E, Retry> SmithyRetryPolicy<O, T, E, Retry> for R
where
R: tower::retry::Policy<Operation<O, Retry>, SdkSuccess<T>, SdkError<E>> + Clone,
O: ParseHttpResponse<Output = Result<T, E>> + Send + Sync + Clone + 'static,
E: Error,
Retry: ClassifyRetry<SdkSuccess<T>, SdkError<E>>,
{
type O = O;
type E = E;
type Retry = Retry;
}