extern crate futures; extern crate tokio_service; use std::io; use self::futures::{Future, IntoFuture}; use self::tokio_service::Service; pub struct SimpleService { inner: Box Box + Send> + Send>, } /// Returns a `Service` backed by the given closure. pub fn simple_service(f: F) -> SimpleService where F: Fn(T) -> R + Send + 'static, R: IntoFuture, R::Future: Send + 'static, { SimpleService { inner: Box::new(move |t| Box::new(f(t).into_future())), } } impl Service for SimpleService { type Request = T; type Response = U; type Future = Box + Send>; type Error = io::Error; fn call(&self, t: T) -> Self::Future { (self.inner)(t) } }