mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
simplify ExtractService's return type (#1842)
This commit is contained in:
parent
79de04d862
commit
6cbf27508a
@ -163,7 +163,7 @@ where
|
||||
{
|
||||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse;
|
||||
type Error = (Error, ServiceRequest);
|
||||
type Error = Error;
|
||||
type Config = ();
|
||||
type Service = ExtractService<T, S>;
|
||||
type InitError = ();
|
||||
@ -192,7 +192,7 @@ where
|
||||
{
|
||||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse;
|
||||
type Error = (Error, ServiceRequest);
|
||||
type Error = Error;
|
||||
type Future = ExtractResponse<T, S>;
|
||||
|
||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
@ -220,7 +220,7 @@ where
|
||||
Error = Infallible,
|
||||
>,
|
||||
{
|
||||
type Output = Result<ServiceResponse, (Error, ServiceRequest)>;
|
||||
type Output = Result<ServiceResponse, Error>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
loop {
|
||||
@ -231,7 +231,7 @@ where
|
||||
match res {
|
||||
Err(e) => {
|
||||
let req = ServiceRequest::new(req);
|
||||
return Poll::Ready(Err((e.into(), req)));
|
||||
return Poll::Ready(Ok(req.error_response(e.into())));
|
||||
}
|
||||
Ok(item) => {
|
||||
let fut = srv.call((item, req));
|
||||
|
32
src/route.rs
32
src/route.rs
@ -234,7 +234,7 @@ impl Route {
|
||||
|
||||
struct RouteNewService<T>
|
||||
where
|
||||
T: ServiceFactory<Request = ServiceRequest, Error = (Error, ServiceRequest)>,
|
||||
T: ServiceFactory<Request = ServiceRequest, Error = Error>,
|
||||
{
|
||||
service: T,
|
||||
}
|
||||
@ -245,7 +245,7 @@ where
|
||||
Config = (),
|
||||
Request = ServiceRequest,
|
||||
Response = ServiceResponse,
|
||||
Error = (Error, ServiceRequest),
|
||||
Error = Error,
|
||||
>,
|
||||
T::Future: 'static,
|
||||
T::Service: 'static,
|
||||
@ -262,7 +262,7 @@ where
|
||||
Config = (),
|
||||
Request = ServiceRequest,
|
||||
Response = ServiceResponse,
|
||||
Error = (Error, ServiceRequest),
|
||||
Error = Error,
|
||||
>,
|
||||
T::Future: 'static,
|
||||
T::Service: 'static,
|
||||
@ -297,11 +297,7 @@ struct RouteServiceWrapper<T: Service> {
|
||||
impl<T> Service for RouteServiceWrapper<T>
|
||||
where
|
||||
T::Future: 'static,
|
||||
T: Service<
|
||||
Request = ServiceRequest,
|
||||
Response = ServiceResponse,
|
||||
Error = (Error, ServiceRequest),
|
||||
>,
|
||||
T: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
|
||||
{
|
||||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse;
|
||||
@ -309,27 +305,11 @@ where
|
||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.service.poll_ready(cx).map_err(|(e, _)| e)
|
||||
self.service.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||
// let mut fut = self.service.call(req);
|
||||
self.service
|
||||
.call(req)
|
||||
.map(|res| match res {
|
||||
Ok(res) => Ok(res),
|
||||
Err((err, req)) => Ok(req.error_response(err)),
|
||||
})
|
||||
.boxed_local()
|
||||
|
||||
// match fut.poll() {
|
||||
// Poll::Ready(Ok(res)) => Either::Left(ok(res)),
|
||||
// Poll::Ready(Err((e, req))) => Either::Left(ok(req.error_response(e))),
|
||||
// Poll::Pending => Either::Right(Box::new(fut.then(|res| match res {
|
||||
// Ok(res) => Ok(res),
|
||||
// Err((err, req)) => Ok(req.error_response(err)),
|
||||
// }))),
|
||||
// }
|
||||
Box::pin(self.service.call(req))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user