tower_http_util/service/
mod.rs1mod as_service;
4mod into_service;
5
6pub use self::as_service::AsService;
7pub use self::into_service::IntoService;
8
9use futures::{Future, Poll};
10use http::{Request, Response};
11use http_body::Body;
12use tower_service::Service;
13
14use crate::sealed::Sealed;
15
16pub trait HttpService<RequestBody>: Sealed<RequestBody> {
22 type ResponseBody: Body;
24
25 type Error;
27
28 type Future: Future<Item = Response<Self::ResponseBody>, Error = Self::Error>;
30
31 fn poll_ready(&mut self) -> Poll<(), Self::Error>;
33
34 fn call(&mut self, request: Request<RequestBody>) -> Self::Future;
36
37 fn into_service(self) -> IntoService<Self>
45 where
46 Self: Sized,
47 {
48 IntoService::new(self)
49 }
50
51 fn as_service(&mut self) -> AsService<Self>
53 where
54 Self: Sized,
55 {
56 AsService::new(self)
57 }
58}
59
60impl<T, B1, B2> HttpService<B1> for T
61where
62 T: Service<Request<B1>, Response = Response<B2>>,
63 B2: Body,
64{
65 type ResponseBody = B2;
66 type Error = T::Error;
67 type Future = T::Future;
68
69 fn poll_ready(&mut self) -> Poll<(), Self::Error> {
70 Service::poll_ready(self)
71 }
72
73 fn call(&mut self, request: Request<B1>) -> Self::Future {
74 Service::call(self, request)
75 }
76}
77
78impl<T, B1, B2> Sealed<B1> for T
79where
80 T: Service<Request<B1>, Response = Response<B2>>,
81 B2: Body,
82{
83}