finchers_runtime/
service.rs1use futures::{self, Future};
7use http::{Request, Response};
8use std::sync::Arc;
9
10pub trait Payload {
12 type Data: AsRef<[u8]> + 'static;
14
15 type Error;
17
18 fn poll_data(&mut self) -> futures::Poll<Option<Self::Data>, Self::Error>;
20}
21
22pub trait NewHttpService {
24 type RequestBody;
26
27 type ResponseBody;
29
30 type Error;
32
33 type Service: HttpService<RequestBody = Self::RequestBody, ResponseBody = Self::ResponseBody, Error = Self::Error>;
35
36 type InitError;
38
39 type Future: Future<Item = Self::Service, Error = Self::InitError>;
41
42 fn new_service(&self) -> Self::Future;
44}
45
46impl<S: NewHttpService> NewHttpService for Box<S> {
47 type RequestBody = S::RequestBody;
48 type ResponseBody = S::ResponseBody;
49 type Error = S::Error;
50 type Service = S::Service;
51 type Future = S::Future;
52 type InitError = S::InitError;
53
54 fn new_service(&self) -> Self::Future {
55 (**self).new_service()
56 }
57}
58
59impl<S: NewHttpService> NewHttpService for Arc<S> {
60 type RequestBody = S::RequestBody;
61 type ResponseBody = S::ResponseBody;
62 type Error = S::Error;
63 type Service = S::Service;
64 type Future = S::Future;
65 type InitError = S::InitError;
66
67 fn new_service(&self) -> Self::Future {
68 (**self).new_service()
69 }
70}
71
72pub trait HttpService {
74 type RequestBody;
76
77 type ResponseBody;
79
80 type Error;
82
83 type Future: Future<Item = Response<Self::ResponseBody>, Error = Self::Error>;
85
86 fn call(&mut self, request: Request<Self::RequestBody>) -> Self::Future;
89}
90
91impl<S: HttpService> HttpService for Box<S> {
92 type RequestBody = S::RequestBody;
93 type ResponseBody = S::ResponseBody;
94 type Error = S::Error;
95 type Future = S::Future;
96
97 fn call(&mut self, request: Request<Self::RequestBody>) -> Self::Future {
98 (**self).call(request)
99 }
100}