Implement DirectService for ServiceFn (#127)
This commit is contained in:
parent
9bae225918
commit
72508ff4ba
|
@ -7,3 +7,4 @@ publish = false
|
|||
[dependencies]
|
||||
futures = "0.1"
|
||||
tower-service = { version = "0.1", path = "../tower-service" }
|
||||
tower-direct-service = { version = "0.1", path = "../tower-direct-service" }
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate tower_direct_service;
|
||||
extern crate tower_service;
|
||||
|
||||
pub mod boxed;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use futures::{IntoFuture, Poll};
|
||||
use tower_direct_service::DirectService;
|
||||
use tower_service::Service;
|
||||
|
||||
/// A `Service` implemented by a closure.
|
||||
|
@ -31,3 +32,28 @@ where T: Fn(Request) -> F,
|
|||
(self.f)(req).into_future()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F, Request> DirectService<Request> for ServiceFn<T>
|
||||
where T: Fn(Request) -> F,
|
||||
F: IntoFuture,
|
||||
{
|
||||
type Response = F::Item;
|
||||
type Error = F::Error;
|
||||
type Future = F::Future;
|
||||
|
||||
fn poll_ready(&mut self) -> Poll<(), F::Error> {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
fn poll_service(&mut self) -> Poll<(), F::Error> {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
fn poll_close(&mut self) -> Poll<(), F::Error> {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
fn call(&mut self, req: Request) -> Self::Future {
|
||||
(self.f)(req).into_future()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue