1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::task::{Context, Poll};
use futures_util::future;
use hyper::{service::Service, Body, Request};
pub struct RouterService<T>
where
T: Service<Request<Body>> + Clone,
{
inner: T,
}
impl<T: Service<Request<Body>> + Clone> RouterService<T> {
pub fn new(inner: T) -> RouterService<T> {
RouterService { inner }
}
}
impl<I, T> Service<T> for RouterService<I>
where
I: Service<Request<Body>> + Clone,
{
type Response = I;
type Error = std::io::Error;
type Future = future::Ready<Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Ok(()).into()
}
fn call(&mut self, _: T) -> Self::Future {
future::ok(self.inner.clone())
}
}