tower_http_util/service/
as_service.rs

1use super::HttpService;
2use futures::Poll;
3use http::{Request, Response};
4use tower_service::Service;
5
6/// Wraps an `HttpService` reference, implementing `tower_service::Service`.
7///
8/// See [`as_service`] function documentation for more details.
9///
10/// [`as_service`]: #
11#[derive(Debug)]
12pub struct AsService<'a, T: 'a> {
13    inner: &'a mut T,
14}
15
16impl<'a, T> AsService<'a, T> {
17    pub(crate) fn new(inner: &'a mut T) -> AsService<'a, T> {
18        AsService { inner }
19    }
20}
21
22impl<'a, T, ReqBody> Service<Request<ReqBody>> for AsService<'a, T>
23where
24    T: HttpService<ReqBody>,
25{
26    type Response = Response<T::ResponseBody>;
27    type Error = T::Error;
28    type Future = T::Future;
29
30    fn poll_ready(&mut self) -> Poll<(), Self::Error> {
31        self.inner.poll_ready()
32    }
33
34    fn call(&mut self, request: Request<ReqBody>) -> Self::Future {
35        self.inner.call(request)
36    }
37}