1use std::error::Error as StdError;
2use std::future::Future;
34use crate::body::Body;
5use crate::service::service::Service;
6use crate::{Request, Response};
78/// An asynchronous function from `Request` to `Response`.
9pub trait HttpService<ReqBody>: sealed::Sealed<ReqBody> {
10/// The `Body` body of the `http::Response`.
11type ResBody: Body;
1213/// The error type that can occur within this `Service`.
14 ///
15 /// Note: Returning an `Error` to a hyper server will cause the connection
16 /// to be abruptly aborted. In most cases, it is better to return a `Response`
17 /// with a 4xx or 5xx status code.
18type Error: Into<Box<dyn StdError + Send + Sync>>;
1920/// The `Future` returned by this `Service`.
21type Future: Future<Output = Result<Response<Self::ResBody>, Self::Error>>;
2223#[doc(hidden)]
24fn call(&mut self, req: Request<ReqBody>) -> Self::Future;
25}
2627impl<T, B1, B2> HttpService<B1> for T
28where
29T: Service<Request<B1>, Response = Response<B2>>,
30 B2: Body,
31 T::Error: Into<Box<dyn StdError + Send + Sync>>,
32{
33type ResBody = B2;
3435type Error = T::Error;
36type Future = T::Future;
3738fn call(&mut self, req: Request<B1>) -> Self::Future {
39 Service::call(self, req)
40 }
41}
4243impl<T, B1, B2> sealed::Sealed<B1> for T
44where
45T: Service<Request<B1>, Response = Response<B2>>,
46 B2: Body,
47{
48}
4950mod sealed {
51pub trait Sealed<T> {}
52}