use http_body::Body; use std::future::Future; use std::task::{Context, Poll}; use tower_service::Service; /// Definition of the gRPC trait alias for [`tower_service`]. /// /// This trait enforces that all tower services provided to [`Grpc`] implements /// the correct traits. /// /// [`Grpc`]: ../client/struct.Grpc.html /// [`tower_service`]: https://docs.rs/tower-service pub trait GrpcService { /// Responses body given by the service. type ResponseBody: Body; /// Errors produced by the service. type Error: Into; /// The future response value. type Future: Future, Self::Error>>; /// Returns `Ready` when the service is able to process requests. /// /// Reference [`Service::poll_ready`]. fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll>; /// Process the request and return the response asynchronously. /// /// Reference [`Service::call`]. fn call(&mut self, request: http::Request) -> Self::Future; } impl GrpcService for T where T: Service, Response = http::Response>, T::Error: Into, ResBody: Body, ::Error: Into, { type ResponseBody = ResBody; type Error = T::Error; type Future = T::Future; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { Service::poll_ready(self, cx) } fn call(&mut self, request: http::Request) -> Self::Future { Service::call(self, request) } }