use crate::{Request, Response, Status, Streaming}; use std::future::Future; use tokio_stream::Stream; use tower_service::Service; /// A specialization of tower_service::Service. /// /// Existing tower_service::Service implementations with the correct form will /// automatically implement `UnaryService`. pub trait UnaryService { /// Protobuf response message type type Response; /// Response future type Future: Future, Status>>; /// Call the service fn call(&mut self, request: Request) -> Self::Future; } impl UnaryService for T where T: Service, Response = Response, Error = crate::Status>, { type Response = M2; type Future = T::Future; fn call(&mut self, request: Request) -> Self::Future { Service::call(self, request) } } /// A specialization of tower_service::Service. /// /// Existing tower_service::Service implementations with the correct form will /// automatically implement `ServerStreamingService`. pub trait ServerStreamingService { /// Protobuf response message type type Response; /// Stream of outbound response messages type ResponseStream: Stream>; /// Response future type Future: Future, Status>>; /// Call the service fn call(&mut self, request: Request) -> Self::Future; } impl ServerStreamingService for T where T: Service, Response = Response, Error = crate::Status>, S: Stream>, { type Response = M2; type ResponseStream = S; type Future = T::Future; fn call(&mut self, request: Request) -> Self::Future { Service::call(self, request) } } /// A specialization of tower_service::Service. /// /// Existing tower_service::Service implementations with the correct form will /// automatically implement `ClientStreamingService`. pub trait ClientStreamingService { /// Protobuf response message type type Response; /// Response future type Future: Future, Status>>; /// Call the service fn call(&mut self, request: Request>) -> Self::Future; } impl ClientStreamingService for T where T: Service>, Response = Response, Error = crate::Status>, { type Response = M2; type Future = T::Future; fn call(&mut self, request: Request>) -> Self::Future { Service::call(self, request) } } /// A specialization of tower_service::Service. /// /// Existing tower_service::Service implementations with the correct form will /// automatically implement `StreamingService`. pub trait StreamingService { /// Protobuf response message type type Response; /// Stream of outbound response messages type ResponseStream: Stream>; /// Response future type Future: Future, Status>>; /// Call the service fn call(&mut self, request: Request>) -> Self::Future; } impl StreamingService for T where T: Service>, Response = Response, Error = crate::Status>, S: Stream>, { type Response = M2; type ResponseStream = S; type Future = T::Future; fn call(&mut self, request: Request>) -> Self::Future { Service::call(self, request) } }