rm tower-util/src/service_fn.rs (#196)

This commit is contained in:
Carl Lerche 2019-03-14 19:51:50 -07:00 committed by GitHub
parent f8d88427aa
commit fd54e47b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 34 deletions

View File

@ -1,34 +0,0 @@
use futures::{IntoFuture, Poll};
use tower_service::Service;
/// A `Service` implemented by a closure.
pub struct ServiceFn<T> {
f: T,
}
// ===== impl ServiceFn =====
impl<T> ServiceFn<T> {
/// Returns a new `NewServiceFn` with the given closure.
pub fn new(f: T) -> Self {
ServiceFn { f }
}
}
impl<T, F, Request> Service<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 call(&mut self, req: Request) -> Self::Future {
(self.f)(req).into_future()
}
}