1use std::error::Error as StdError;
2use std::future::Future;
3
4use crate::body::Body;
5use crate::service::service::Service;
6use crate::{Request, Response};
7
8pub trait HttpService<ReqBody>: sealed::Sealed<ReqBody> {
10 type ResBody: Body;
12
13 type Error: Into<Box<dyn StdError + Send + Sync>>;
19
20 type Future: Future<Output = Result<Response<Self::ResBody>, Self::Error>>;
22
23 #[doc(hidden)]
24 fn call(&mut self, req: Request<ReqBody>) -> Self::Future;
25}
26
27impl<T, B1, B2> HttpService<B1> for T
28where
29 T: Service<Request<B1>, Response = Response<B2>>,
30 B2: Body,
31 T::Error: Into<Box<dyn StdError + Send + Sync>>,
32{
33 type ResBody = B2;
34
35 type Error = T::Error;
36 type Future = T::Future;
37
38 fn call(&mut self, req: Request<B1>) -> Self::Future {
39 Service::call(self, req)
40 }
41}
42
43impl<T, B1, B2> sealed::Sealed<B1> for T
44where
45 T: Service<Request<B1>, Response = Response<B2>>,
46 B2: Body,
47{
48}
49
50mod sealed {
51 pub trait Sealed<T> {}
52}