2019-05-12 17:34:51 +02:00
|
|
|
use std::convert::Infallible;
|
2018-04-14 01:02:01 +02:00
|
|
|
use std::marker::PhantomData;
|
2017-10-07 06:48:14 +02:00
|
|
|
|
2019-05-05 04:43:49 +02:00
|
|
|
use actix_http::{Error, Payload, Response};
|
2019-05-12 17:34:51 +02:00
|
|
|
use actix_service::{NewService, Service};
|
2019-03-02 07:51:32 +01:00
|
|
|
use futures::future::{ok, FutureResult};
|
|
|
|
use futures::{try_ready, Async, Future, IntoFuture, Poll};
|
2018-05-02 02:30:06 +02:00
|
|
|
|
2019-03-03 22:53:31 +01:00
|
|
|
use crate::extract::FromRequest;
|
2019-03-02 07:51:32 +01:00
|
|
|
use crate::request::HttpRequest;
|
|
|
|
use crate::responder::Responder;
|
2019-04-07 23:43:07 +02:00
|
|
|
use crate::service::{ServiceRequest, ServiceResponse};
|
2017-11-03 21:35:34 +01:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
/// Handler converter factory
|
|
|
|
pub trait Factory<T, R>: Clone
|
|
|
|
where
|
|
|
|
R: Responder,
|
|
|
|
{
|
|
|
|
fn call(&self, param: T) -> R;
|
2018-03-10 18:39:43 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
impl<F, R> Factory<(), R> for F
|
2018-04-14 01:02:01 +02:00
|
|
|
where
|
2019-04-04 22:17:55 +02:00
|
|
|
F: Fn() -> R + Clone,
|
|
|
|
R: Responder,
|
2018-03-10 18:39:43 +01:00
|
|
|
{
|
2019-03-02 07:51:32 +01:00
|
|
|
fn call(&self, _: ()) -> R {
|
|
|
|
(self)()
|
2018-03-10 18:39:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
#[doc(hidden)]
|
2019-03-07 20:09:42 +01:00
|
|
|
pub struct Handler<F, T, R>
|
2018-04-14 01:02:01 +02:00
|
|
|
where
|
2019-03-02 07:51:32 +01:00
|
|
|
F: Factory<T, R>,
|
|
|
|
R: Responder,
|
2018-04-03 01:19:18 +02:00
|
|
|
{
|
2019-03-02 07:51:32 +01:00
|
|
|
hnd: F,
|
|
|
|
_t: PhantomData<(T, R)>,
|
2018-04-03 01:19:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 20:09:42 +01:00
|
|
|
impl<F, T, R> Handler<F, T, R>
|
2018-06-11 13:05:41 +02:00
|
|
|
where
|
2019-03-02 07:51:32 +01:00
|
|
|
F: Factory<T, R>,
|
|
|
|
R: Responder,
|
2018-06-11 13:05:41 +02:00
|
|
|
{
|
2019-03-02 07:51:32 +01:00
|
|
|
pub fn new(hnd: F) -> Self {
|
2019-03-07 20:09:42 +01:00
|
|
|
Handler {
|
2019-03-02 07:51:32 +01:00
|
|
|
hnd,
|
|
|
|
_t: PhantomData,
|
2018-06-11 13:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 08:06:21 +02:00
|
|
|
|
|
|
|
impl<F, T, R> Clone for Handler<F, T, R>
|
2019-03-02 07:51:32 +01:00
|
|
|
where
|
|
|
|
F: Factory<T, R>,
|
2019-04-04 22:17:55 +02:00
|
|
|
R: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
{
|
2019-04-08 08:06:21 +02:00
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self {
|
2019-03-02 07:51:32 +01:00
|
|
|
hnd: self.hnd.clone(),
|
|
|
|
_t: PhantomData,
|
2019-04-08 08:06:21 +02:00
|
|
|
}
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
2017-12-21 05:30:54 +01:00
|
|
|
}
|
|
|
|
|
2019-04-08 08:06:21 +02:00
|
|
|
impl<F, T, R> Service for Handler<F, T, R>
|
2018-04-14 01:02:01 +02:00
|
|
|
where
|
2019-03-02 07:51:32 +01:00
|
|
|
F: Factory<T, R>,
|
2019-04-04 22:17:55 +02:00
|
|
|
R: Responder,
|
2017-10-15 23:17:41 +02:00
|
|
|
{
|
2019-03-09 18:49:11 +01:00
|
|
|
type Request = (T, HttpRequest);
|
2019-03-02 07:51:32 +01:00
|
|
|
type Response = ServiceResponse;
|
2019-05-12 17:34:51 +02:00
|
|
|
type Error = Infallible;
|
2019-03-07 20:09:42 +01:00
|
|
|
type Future = HandlerServiceResponse<<R::Future as IntoFuture>::Future>;
|
2017-10-15 23:17:41 +02:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
|
|
|
Ok(Async::Ready(()))
|
2017-10-15 23:17:41 +02:00
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
fn call(&mut self, (param, req): (T, HttpRequest)) -> Self::Future {
|
2019-03-03 22:53:31 +01:00
|
|
|
let fut = self.hnd.call(param).respond_to(&req).into_future();
|
2019-03-07 20:09:42 +01:00
|
|
|
HandlerServiceResponse {
|
2019-03-02 07:51:32 +01:00
|
|
|
fut,
|
|
|
|
req: Some(req),
|
2018-05-02 02:30:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 20:09:42 +01:00
|
|
|
pub struct HandlerServiceResponse<T> {
|
2019-03-02 07:51:32 +01:00
|
|
|
fut: T,
|
|
|
|
req: Option<HttpRequest>,
|
2017-11-29 04:49:17 +01:00
|
|
|
}
|
|
|
|
|
2019-03-07 20:09:42 +01:00
|
|
|
impl<T> Future for HandlerServiceResponse<T>
|
2019-03-02 07:51:32 +01:00
|
|
|
where
|
|
|
|
T: Future<Item = Response>,
|
|
|
|
T::Error: Into<Error>,
|
|
|
|
{
|
|
|
|
type Item = ServiceResponse;
|
2019-05-12 17:34:51 +02:00
|
|
|
type Error = Infallible;
|
2019-03-02 07:51:32 +01:00
|
|
|
|
|
|
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
|
|
|
match self.fut.poll() {
|
|
|
|
Ok(Async::Ready(res)) => Ok(Async::Ready(ServiceResponse::new(
|
|
|
|
self.req.take().unwrap(),
|
|
|
|
res,
|
|
|
|
))),
|
|
|
|
Ok(Async::NotReady) => Ok(Async::NotReady),
|
|
|
|
Err(e) => {
|
|
|
|
let res: Response = e.into().into();
|
|
|
|
Ok(Async::Ready(ServiceResponse::new(
|
|
|
|
self.req.take().unwrap(),
|
|
|
|
res,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
2017-11-29 04:49:17 +01:00
|
|
|
}
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
2017-11-29 04:49:17 +01:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
/// Async handler converter factory
|
|
|
|
pub trait AsyncFactory<T, R>: Clone + 'static
|
|
|
|
where
|
|
|
|
R: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
R::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
R::Error: Into<Error>,
|
|
|
|
{
|
|
|
|
fn call(&self, param: T) -> R;
|
|
|
|
}
|
2018-05-02 02:19:15 +02:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
impl<F, R> AsyncFactory<(), R> for F
|
|
|
|
where
|
|
|
|
F: Fn() -> R + Clone + 'static,
|
|
|
|
R: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
R::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
R::Error: Into<Error>,
|
|
|
|
{
|
|
|
|
fn call(&self, _: ()) -> R {
|
|
|
|
(self)()
|
2017-11-29 04:49:17 +01:00
|
|
|
}
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
2017-12-09 22:25:06 +01:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
#[doc(hidden)]
|
2019-03-07 20:09:42 +01:00
|
|
|
pub struct AsyncHandler<F, T, R>
|
2019-03-02 07:51:32 +01:00
|
|
|
where
|
|
|
|
F: AsyncFactory<T, R>,
|
|
|
|
R: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
R::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
R::Error: Into<Error>,
|
|
|
|
{
|
|
|
|
hnd: F,
|
|
|
|
_t: PhantomData<(T, R)>,
|
|
|
|
}
|
2018-05-02 02:19:15 +02:00
|
|
|
|
2019-03-07 20:09:42 +01:00
|
|
|
impl<F, T, R> AsyncHandler<F, T, R>
|
2019-03-02 07:51:32 +01:00
|
|
|
where
|
|
|
|
F: AsyncFactory<T, R>,
|
|
|
|
R: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
R::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
R::Error: Into<Error>,
|
|
|
|
{
|
|
|
|
pub fn new(hnd: F) -> Self {
|
2019-03-07 20:09:42 +01:00
|
|
|
AsyncHandler {
|
2019-03-02 07:51:32 +01:00
|
|
|
hnd,
|
|
|
|
_t: PhantomData,
|
2017-12-09 22:25:06 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-29 04:49:17 +01:00
|
|
|
}
|
2019-04-08 08:06:21 +02:00
|
|
|
|
|
|
|
impl<F, T, R> Clone for AsyncHandler<F, T, R>
|
2019-03-02 07:51:32 +01:00
|
|
|
where
|
|
|
|
F: AsyncFactory<T, R>,
|
|
|
|
R: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
R::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
R::Error: Into<Error>,
|
|
|
|
{
|
2019-04-08 08:06:21 +02:00
|
|
|
fn clone(&self) -> Self {
|
|
|
|
AsyncHandler {
|
2019-03-02 07:51:32 +01:00
|
|
|
hnd: self.hnd.clone(),
|
|
|
|
_t: PhantomData,
|
2019-04-08 08:06:21 +02:00
|
|
|
}
|
2017-12-03 01:37:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 08:06:21 +02:00
|
|
|
impl<F, T, R> Service for AsyncHandler<F, T, R>
|
2019-03-02 07:51:32 +01:00
|
|
|
where
|
|
|
|
F: AsyncFactory<T, R>,
|
|
|
|
R: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
R::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
R::Error: Into<Error>,
|
|
|
|
{
|
2019-03-09 18:49:11 +01:00
|
|
|
type Request = (T, HttpRequest);
|
2019-03-02 07:51:32 +01:00
|
|
|
type Response = ServiceResponse;
|
2019-05-12 17:34:51 +02:00
|
|
|
type Error = Infallible;
|
2019-03-07 20:09:42 +01:00
|
|
|
type Future = AsyncHandlerServiceResponse<R::Future>;
|
2017-12-02 06:29:22 +01:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
|
|
|
Ok(Async::Ready(()))
|
2017-12-03 01:37:21 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
fn call(&mut self, (param, req): (T, HttpRequest)) -> Self::Future {
|
2019-03-07 20:09:42 +01:00
|
|
|
AsyncHandlerServiceResponse {
|
2019-03-02 07:51:32 +01:00
|
|
|
fut: self.hnd.call(param).into_future(),
|
2019-04-22 23:22:08 +02:00
|
|
|
fut2: None,
|
2019-03-02 07:51:32 +01:00
|
|
|
req: Some(req),
|
2017-12-03 01:37:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
#[doc(hidden)]
|
2019-04-22 23:22:08 +02:00
|
|
|
pub struct AsyncHandlerServiceResponse<T>
|
|
|
|
where
|
|
|
|
T: Future,
|
|
|
|
T::Item: Responder,
|
|
|
|
{
|
2019-03-02 07:51:32 +01:00
|
|
|
fut: T,
|
2019-04-22 23:22:08 +02:00
|
|
|
fut2: Option<<<T::Item as Responder>::Future as IntoFuture>::Future>,
|
2019-03-02 07:51:32 +01:00
|
|
|
req: Option<HttpRequest>,
|
2018-05-02 02:19:15 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 20:09:42 +01:00
|
|
|
impl<T> Future for AsyncHandlerServiceResponse<T>
|
2018-08-23 18:48:01 +02:00
|
|
|
where
|
2019-03-02 07:51:32 +01:00
|
|
|
T: Future,
|
2019-04-22 23:22:08 +02:00
|
|
|
T::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
T::Error: Into<Error>,
|
2018-05-02 02:19:15 +02:00
|
|
|
{
|
2019-03-02 07:51:32 +01:00
|
|
|
type Item = ServiceResponse;
|
2019-05-12 17:34:51 +02:00
|
|
|
type Error = Infallible;
|
2019-03-02 07:51:32 +01:00
|
|
|
|
|
|
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
2019-04-22 23:22:08 +02:00
|
|
|
if let Some(ref mut fut) = self.fut2 {
|
|
|
|
return match fut.poll() {
|
|
|
|
Ok(Async::Ready(res)) => Ok(Async::Ready(ServiceResponse::new(
|
|
|
|
self.req.take().unwrap(),
|
|
|
|
res,
|
|
|
|
))),
|
|
|
|
Ok(Async::NotReady) => Ok(Async::NotReady),
|
|
|
|
Err(e) => {
|
|
|
|
let res: Response = e.into().into();
|
|
|
|
Ok(Async::Ready(ServiceResponse::new(
|
|
|
|
self.req.take().unwrap(),
|
|
|
|
res,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
match self.fut.poll() {
|
2019-04-22 23:22:08 +02:00
|
|
|
Ok(Async::Ready(res)) => {
|
|
|
|
self.fut2 =
|
|
|
|
Some(res.respond_to(self.req.as_ref().unwrap()).into_future());
|
|
|
|
return self.poll();
|
|
|
|
}
|
2019-03-02 07:51:32 +01:00
|
|
|
Ok(Async::NotReady) => Ok(Async::NotReady),
|
|
|
|
Err(e) => {
|
|
|
|
let res: Response = e.into().into();
|
|
|
|
Ok(Async::Ready(ServiceResponse::new(
|
|
|
|
self.req.take().unwrap(),
|
|
|
|
res,
|
|
|
|
)))
|
|
|
|
}
|
2018-01-03 08:43:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
/// Extract arguments from request
|
2019-04-13 23:50:54 +02:00
|
|
|
pub struct Extract<T: FromRequest, S> {
|
2019-04-08 08:06:21 +02:00
|
|
|
service: S,
|
2019-04-13 23:50:54 +02:00
|
|
|
_t: PhantomData<T>,
|
2018-01-03 08:43:17 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
impl<T: FromRequest, S> Extract<T, S> {
|
2019-05-05 04:43:49 +02:00
|
|
|
pub fn new(service: S) -> Self {
|
2019-03-03 09:57:48 +01:00
|
|
|
Extract {
|
2019-04-08 08:06:21 +02:00
|
|
|
service,
|
2019-03-03 09:57:48 +01:00
|
|
|
_t: PhantomData,
|
|
|
|
}
|
2018-06-21 10:17:27 +02:00
|
|
|
}
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
2018-06-21 10:17:27 +02:00
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
impl<T: FromRequest, S> NewService for Extract<T, S>
|
2019-04-08 08:06:21 +02:00
|
|
|
where
|
2019-05-12 17:34:51 +02:00
|
|
|
S: Service<
|
|
|
|
Request = (T, HttpRequest),
|
|
|
|
Response = ServiceResponse,
|
|
|
|
Error = Infallible,
|
|
|
|
> + Clone,
|
2019-04-08 08:06:21 +02:00
|
|
|
{
|
2019-05-12 17:34:51 +02:00
|
|
|
type Config = ();
|
2019-04-13 23:50:54 +02:00
|
|
|
type Request = ServiceRequest;
|
2019-04-08 08:06:21 +02:00
|
|
|
type Response = ServiceResponse;
|
2019-04-13 23:50:54 +02:00
|
|
|
type Error = (Error, ServiceRequest);
|
2019-03-02 07:51:32 +01:00
|
|
|
type InitError = ();
|
2019-04-13 23:50:54 +02:00
|
|
|
type Service = ExtractService<T, S>;
|
2019-03-02 07:51:32 +01:00
|
|
|
type Future = FutureResult<Self::Service, ()>;
|
2018-07-15 11:12:21 +02:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
fn new_service(&self, _: &()) -> Self::Future {
|
2019-03-03 09:57:48 +01:00
|
|
|
ok(ExtractService {
|
|
|
|
_t: PhantomData,
|
2019-04-08 08:06:21 +02:00
|
|
|
service: self.service.clone(),
|
2019-03-03 09:57:48 +01:00
|
|
|
})
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
2017-11-29 22:26:55 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
pub struct ExtractService<T: FromRequest, S> {
|
2019-04-08 08:06:21 +02:00
|
|
|
service: S,
|
2019-04-13 23:50:54 +02:00
|
|
|
_t: PhantomData<T>,
|
2017-11-29 22:26:55 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
impl<T: FromRequest, S> Service for ExtractService<T, S>
|
2019-04-08 08:06:21 +02:00
|
|
|
where
|
2019-05-12 17:34:51 +02:00
|
|
|
S: Service<
|
|
|
|
Request = (T, HttpRequest),
|
|
|
|
Response = ServiceResponse,
|
|
|
|
Error = Infallible,
|
|
|
|
> + Clone,
|
2019-04-08 08:06:21 +02:00
|
|
|
{
|
2019-04-13 23:50:54 +02:00
|
|
|
type Request = ServiceRequest;
|
2019-04-08 08:06:21 +02:00
|
|
|
type Response = ServiceResponse;
|
2019-04-13 23:50:54 +02:00
|
|
|
type Error = (Error, ServiceRequest);
|
|
|
|
type Future = ExtractResponse<T, S>;
|
2019-03-02 07:51:32 +01:00
|
|
|
|
|
|
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
|
|
|
Ok(Async::Ready(()))
|
2017-11-29 22:26:55 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
2019-05-05 04:43:49 +02:00
|
|
|
let (req, mut payload) = req.into_parts();
|
2019-04-07 23:43:07 +02:00
|
|
|
let fut = T::from_request(&req, &mut payload).into_future();
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
ExtractResponse {
|
2019-04-07 23:43:07 +02:00
|
|
|
fut,
|
2019-04-08 08:06:21 +02:00
|
|
|
fut_s: None,
|
2019-04-07 23:43:07 +02:00
|
|
|
req: Some((req, payload)),
|
2019-04-08 08:06:21 +02:00
|
|
|
service: self.service.clone(),
|
2017-12-03 23:22:04 +01:00
|
|
|
}
|
2017-11-29 22:26:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
pub struct ExtractResponse<T: FromRequest, S: Service> {
|
|
|
|
req: Option<(HttpRequest, Payload)>,
|
2019-04-08 08:06:21 +02:00
|
|
|
service: S,
|
2019-03-03 22:53:31 +01:00
|
|
|
fut: <T::Future as IntoFuture>::Future,
|
2019-04-08 08:06:21 +02:00
|
|
|
fut_s: Option<S::Future>,
|
2017-11-29 22:26:55 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 23:50:54 +02:00
|
|
|
impl<T: FromRequest, S> Future for ExtractResponse<T, S>
|
2019-04-08 08:06:21 +02:00
|
|
|
where
|
2019-05-12 17:34:51 +02:00
|
|
|
S: Service<
|
|
|
|
Request = (T, HttpRequest),
|
|
|
|
Response = ServiceResponse,
|
|
|
|
Error = Infallible,
|
|
|
|
>,
|
2019-04-08 08:06:21 +02:00
|
|
|
{
|
|
|
|
type Item = ServiceResponse;
|
2019-04-13 23:50:54 +02:00
|
|
|
type Error = (Error, ServiceRequest);
|
2017-11-29 22:26:55 +01:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
2019-04-08 08:06:21 +02:00
|
|
|
if let Some(ref mut fut) = self.fut_s {
|
|
|
|
return fut.poll().map_err(|_| panic!());
|
|
|
|
}
|
|
|
|
|
2019-04-07 23:43:07 +02:00
|
|
|
let item = try_ready!(self.fut.poll().map_err(|e| {
|
|
|
|
let (req, payload) = self.req.take().unwrap();
|
|
|
|
let req = ServiceRequest::from_parts(req, payload);
|
|
|
|
(e.into(), req)
|
|
|
|
}));
|
2019-03-02 07:51:32 +01:00
|
|
|
|
2019-04-08 08:06:21 +02:00
|
|
|
self.fut_s = Some(self.service.call((item, self.req.take().unwrap().0)));
|
|
|
|
self.poll()
|
2018-03-30 00:41:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
/// FromRequest trait impl for tuples
|
|
|
|
macro_rules! factory_tuple ({ $(($n:tt, $T:ident)),+} => {
|
|
|
|
impl<Func, $($T,)+ Res> Factory<($($T,)+), Res> for Func
|
2019-04-04 22:17:55 +02:00
|
|
|
where Func: Fn($($T,)+) -> Res + Clone,
|
|
|
|
Res: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
{
|
|
|
|
fn call(&self, param: ($($T,)+)) -> Res {
|
|
|
|
(self)($(param.$n,)+)
|
|
|
|
}
|
|
|
|
}
|
2018-03-30 00:41:13 +02:00
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
impl<Func, $($T,)+ Res> AsyncFactory<($($T,)+), Res> for Func
|
|
|
|
where Func: Fn($($T,)+) -> Res + Clone + 'static,
|
2019-04-04 22:17:55 +02:00
|
|
|
Res: IntoFuture,
|
2019-04-22 23:22:08 +02:00
|
|
|
Res::Item: Responder,
|
2019-03-02 07:51:32 +01:00
|
|
|
Res::Error: Into<Error>,
|
|
|
|
{
|
|
|
|
fn call(&self, param: ($($T,)+)) -> Res {
|
|
|
|
(self)($(param.$n,)+)
|
|
|
|
}
|
2018-03-30 00:41:13 +02:00
|
|
|
}
|
2019-03-02 07:51:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
mod m {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
factory_tuple!((0, A));
|
|
|
|
factory_tuple!((0, A), (1, B));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D), (4, E));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D), (4, E), (5, F));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G), (7, H));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G), (7, H), (8, I));
|
|
|
|
factory_tuple!((0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G), (7, H), (8, I), (9, J));
|
2018-03-30 00:41:13 +02:00
|
|
|
}
|