tower_web/util/http/
new_service.rs1use super::HttpService;
2use util::buf_stream::BufStream;
3
4use futures::Future;
5use http::{Request, Response};
6use tower_service::NewService;
7
8pub trait NewHttpService: sealed::Sealed {
14 type RequestBody: BufStream;
16
17 type ResponseBody: BufStream;
19
20 type Error;
22
23 type Service: HttpService<RequestBody = Self::RequestBody,
25 ResponseBody = Self::ResponseBody,
26 Error = Self::Error>;
27
28 type InitError;
30
31 type Future: Future<Item = Self::Service, Error = Self::InitError>;
33
34 fn new_http_service(&self) -> Self::Future;
36}
37
38impl<T, B1, B2> NewHttpService for T
39where T: NewService<Request = Request<B1>,
40 Response = Response<B2>>,
41 B1: BufStream,
42 B2: BufStream
43{
44 type RequestBody = B1;
45 type ResponseBody = B2;
46 type Error = T::Error;
47 type Service = T::Service;
48 type InitError = T::InitError;
49 type Future = T::Future;
50
51 fn new_http_service(&self) -> Self::Future {
52 NewService::new_service(self)
53 }
54}
55
56impl<T, B1, B2> sealed::Sealed for T
57where T: NewService<Request = Request<B1>,
58 Response = Response<B2>>,
59 B1: BufStream,
60 B2: BufStream
61{}
62
63mod sealed {
64 pub trait Sealed {}
65}