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
39
40
//! A trait alias for [`Service`](tower_service::Service).

use http::{Request, Response};
use http_body::Body;
use tower_service::Service;

use private::Sealed;

#[cfg_attr(not(feature = "hyper"), allow(intra_doc_link_resolution_failure))]
/// An HTTP client (like [`hyper::Client`](hyper_pkg::client::Client)).
///
/// This is just an alias for [`tower_service::Service`](tower_service::Service)
/// introduced to reduce the number of type parameters in `Builder::listen_with_client`.
pub trait HttpService<B>: Service<Request<B>> + Sealed<B> {
    /// Body of the responses given by the service.
    type ResponseBody: Body;
}

impl<S, ReqB, ResB> HttpService<ReqB> for S
where
    S: Service<Request<ReqB>, Response = Response<ResB>> + ?Sized,
    ResB: Body,
{
    type ResponseBody = ResB;
}

mod private {
    use http::{Request, Response};
    use http_body::Body;
    use tower_service::Service;

    pub trait Sealed<B> {}

    impl<S, ReqB, ResB> Sealed<ReqB> for S
    where
        S: Service<Request<ReqB>, Response = Response<ResB>> + ?Sized,
        ResB: Body,
    {
    }
}