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 Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = (Error, ServiceRequest);
|
type Error = Error;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
type Service = ExtractService<T, S>;
|
type Service = ExtractService<T, S>;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -192,7 +192,7 @@ where
|
|||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = (Error, ServiceRequest);
|
type Error = Error;
|
||||||
type Future = ExtractResponse<T, S>;
|
type Future = ExtractResponse<T, S>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
@ -220,7 +220,7 @@ where
|
|||||||
Error = Infallible,
|
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> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
loop {
|
loop {
|
||||||
@ -231,7 +231,7 @@ where
|
|||||||
match res {
|
match res {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let req = ServiceRequest::new(req);
|
let req = ServiceRequest::new(req);
|
||||||
return Poll::Ready(Err((e.into(), req)));
|
return Poll::Ready(Ok(req.error_response(e.into())));
|
||||||
}
|
}
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
let fut = srv.call((item, req));
|
let fut = srv.call((item, req));
|
||||||
|
32
src/route.rs
32
src/route.rs
@ -234,7 +234,7 @@ impl Route {
|
|||||||
|
|
||||||
struct RouteNewService<T>
|
struct RouteNewService<T>
|
||||||
where
|
where
|
||||||
T: ServiceFactory<Request = ServiceRequest, Error = (Error, ServiceRequest)>,
|
T: ServiceFactory<Request = ServiceRequest, Error = Error>,
|
||||||
{
|
{
|
||||||
service: T,
|
service: T,
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ where
|
|||||||
Config = (),
|
Config = (),
|
||||||
Request = ServiceRequest,
|
Request = ServiceRequest,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (Error, ServiceRequest),
|
Error = Error,
|
||||||
>,
|
>,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T::Service: 'static,
|
T::Service: 'static,
|
||||||
@ -262,7 +262,7 @@ where
|
|||||||
Config = (),
|
Config = (),
|
||||||
Request = ServiceRequest,
|
Request = ServiceRequest,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (Error, ServiceRequest),
|
Error = Error,
|
||||||
>,
|
>,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T::Service: 'static,
|
T::Service: 'static,
|
||||||
@ -297,11 +297,7 @@ struct RouteServiceWrapper<T: Service> {
|
|||||||
impl<T> Service for RouteServiceWrapper<T>
|
impl<T> Service for RouteServiceWrapper<T>
|
||||||
where
|
where
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T: Service<
|
T: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
|
||||||
Request = ServiceRequest,
|
|
||||||
Response = ServiceResponse,
|
|
||||||
Error = (Error, ServiceRequest),
|
|
||||||
>,
|
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
@ -309,27 +305,11 @@ where
|
|||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), 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 {
|
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||||
// let mut fut = self.service.call(req);
|
Box::pin(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)),
|
|
||||||
// }))),
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user