feat(service): use tower_service::Service for hyper::service

This commit is contained in:
Lucio Franco
2019-08-20 15:01:06 -04:00
committed by Sean McArthur
parent 53a437c382
commit ec520d5602
11 changed files with 230 additions and 111 deletions

View File

@@ -30,7 +30,7 @@ pub(crate) trait Dispatch {
fn should_poll(&self) -> bool;
}
pub struct Server<S: Service> {
pub struct Server<S: Service<B>, B> {
in_flight: Pin<Box<Option<S::Future>>>,
pub(crate) service: S,
}
@@ -412,11 +412,11 @@ impl<'a, T> Drop for OptGuard<'a, T> {
// ===== impl Server =====
impl<S> Server<S>
impl<S, B> Server<S, B>
where
S: Service,
S: Service<B>,
{
pub fn new(service: S) -> Server<S> {
pub fn new(service: S) -> Server<S, B> {
Server {
in_flight: Box::pin(None),
service: service,
@@ -429,11 +429,11 @@ where
}
// Service is never pinned
impl<S: Service> Unpin for Server<S> {}
impl<S: Service<B>, B> Unpin for Server<S, B> {}
impl<S, Bs> Dispatch for Server<S>
impl<S, Bs> Dispatch for Server<S, Body>
where
S: Service<ReqBody=Body, ResBody=Bs>,
S: Service<Body, ResBody=Bs>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Bs: Payload,
{

View File

@@ -20,7 +20,7 @@ use crate::{Body, Response};
pub(crate) struct Server<T, S, B, E>
where
S: Service,
S: Service<Body>,
B: Payload,
{
exec: E,
@@ -29,7 +29,7 @@ where
}
// TODO: fix me
impl<T, S: Service, B: Payload, E> Unpin for Server<T, S, B, E> {}
impl<T, S: Service<Body>, B: Payload, E> Unpin for Server<T, S, B, E> {}
enum State<T, B>
where
@@ -52,7 +52,7 @@ where
impl<T, S, B, E> Server<T, S, B, E>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<ReqBody=Body, ResBody=B>,
S: Service<Body, ResBody=B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Payload,
B::Data: Unpin,
@@ -90,7 +90,7 @@ where
impl<T, S, B, E> Future for Server<T, S, B, E>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<ReqBody=Body, ResBody=B>,
S: Service<Body, ResBody=B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Payload,
B::Data: Unpin,
@@ -133,7 +133,7 @@ where
fn poll_server<S, E>(&mut self, cx: &mut task::Context<'_>, service: &mut S, exec: &mut E) -> Poll<crate::Result<()>>
where
S: Service<
ReqBody=Body,
Body,
ResBody=B,
>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,