dubbo/triple/server/
service.rs1use futures_util::{Future, Stream};
19use tower_service::Service;
20
21use crate::{
22 invocation::{Request, Response},
23 triple::decode::Decoding,
24};
25
26pub trait StreamingSvc<R> {
27 type Response;
28
29 type ResponseStream: Stream<Item = Result<Self::Response, crate::status::Status>>;
30
31 type Future: Future<Output = Result<Response<Self::ResponseStream>, crate::status::Status>>;
32
33 fn call(&mut self, req: Request<Decoding<R>>) -> Self::Future;
34}
35
36impl<T, S, M1, M2> StreamingSvc<M1> for T
37where
38 T: Service<Request<Decoding<M1>>, Response = Response<S>, Error = crate::status::Status>,
39 S: Stream<Item = Result<M2, crate::status::Status>>,
40{
41 type Response = M2;
42
43 type ResponseStream = S;
44
45 type Future = T::Future;
46
47 fn call(&mut self, req: Request<Decoding<M1>>) -> Self::Future {
48 Service::call(self, req)
49 }
50}
51
52pub trait UnarySvc<R> {
53 type Response;
54 type Future: Future<Output = Result<Response<Self::Response>, crate::status::Status>>;
55
56 fn call(&mut self, req: Request<R>) -> Self::Future;
57}
58
59impl<T, M1, M2> UnarySvc<M1> for T
60where
61 T: Service<Request<M1>, Response = Response<M2>, Error = crate::status::Status>,
62{
63 type Response = M2;
64
65 type Future = T::Future;
66
67 fn call(&mut self, req: Request<M1>) -> Self::Future {
68 T::call(self, req)
69 }
70}
71
72pub trait ClientStreamingSvc<R> {
73 type Response;
74 type Future: Future<Output = Result<Response<Self::Response>, crate::status::Status>>;
75
76 fn call(&mut self, req: Request<Decoding<R>>) -> Self::Future;
77}
78
79impl<T, M1, M2> ClientStreamingSvc<M1> for T
80where
81 T: Service<Request<Decoding<M1>>, Response = Response<M2>, Error = crate::status::Status>,
82{
83 type Response = M2;
84
85 type Future = T::Future;
86
87 fn call(&mut self, req: Request<Decoding<M1>>) -> Self::Future {
88 T::call(self, req)
89 }
90}
91
92pub trait ServerStreamingSvc<R> {
93 type Response;
94
95 type ResponseStream: Stream<Item = Result<Self::Response, crate::status::Status>>;
96
97 type Future: Future<Output = Result<Response<Self::ResponseStream>, crate::status::Status>>;
98
99 fn call(&mut self, req: Request<R>) -> Self::Future;
100}
101
102impl<T, S, M1, M2> ServerStreamingSvc<M1> for T
103where
104 T: Service<Request<M1>, Response = Response<S>, Error = crate::status::Status>,
105 S: Stream<Item = Result<M2, crate::status::Status>>,
106{
107 type Response = M2;
108
109 type ResponseStream = S;
110
111 type Future = T::Future;
112
113 fn call(&mut self, req: Request<M1>) -> Self::Future {
114 Service::call(self, req)
115 }
116}