Unverified Commit 50725dca authored by Alexandru Vasile's avatar Alexandru Vasile
Browse files

http: Implement equivalent of `make_service_fn`



Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
parent aa0936ab
......@@ -554,6 +554,30 @@ impl<M: Middleware> hyper::service::Service<hyper::Request<hyper::Body>> for RPS
}
}
/// JsonRPSee service compatible with `tower`.
///
/// # Note
/// This is similar to [`hyper::service::make_service_fn`].
pub struct RPSeeServerMakeSvc<M> {
inner: RPSeeSvcData<M>,
}
impl<T, M: Clone + Send + 'static> hyper::service::Service<T> for RPSeeServerMakeSvc<M> {
type Response = RPSeeServerSvc<M>;
type Error = hyper::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _: &mut Context) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, _connection: T) -> Self::Future {
let inner = self.inner.clone();
let fut = async move { Ok(RPSeeServerSvc { inner }) };
Box::pin(fut)
}
}
/// An HTTP JSON RPC server.
#[derive(Debug)]
pub struct Server<M = ()> {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment